分配从MSBuild中的属性获取的参数值 [英] Assign parameter value taken from a property in MSBuild
问题描述
我正在尝试使用MSBuild和内联任务将批处理脚本和C#代码结合起来.看起来传递命令行参数的唯一方法是使用属性(msbuild中的/property
命令行开关),并且唯一从内联任务访问外部内容的一种方法是使用属性.
I'm trying to combine batch script and C# code using MSBuild and inline tasks.Looks like the only one way to pass a command line argument is to use a properties (/property
command line switch in msbuild) and the only one way to access something external from the inline task is to use properties.
如何组合MSBuild中的属性和参数,以使其可以在内联任务中访问?
How can I combine the properties and parameters in MSBuild in way to make them accessible in the inline task?
这是一个示例脚本(应另存为.bat
或.cmd
):
Here's an example script (should be saves as .bat
or .cmd
) :
<!-- :
@echo off
echo -^- FROM BATCH
for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*msbuild.exe") do set "msb=%%#"
if not defined msb (
echo no .net framework installed
exit /b 10
)
rem :::::::::: calling msbuid :::::::::
call %msb% /nologo /noconsolelogger "%~dpsfnx0" /property:"H=From C#"
rem ::::::::::::::::::::::::::::::::::::
exit /b %errorlevel%
-->
<Project ToolsVersion="$(MSBuildToolsVersion)" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="_">
<_/>
</Target>
<UsingTask
TaskName="_"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll" >
<ParameterGroup >
<Z ParameterType="System.String">$(H)</Z>
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
System.Console.WriteLine("-- "+"$(H)");
]]>
</Code>
</Task>
</UsingTask>
</Project>
作为/property:H=Hello
传递给,目的是要打印此脚本
--Hello--
,但仅打印----
as /property:H=Hello
is passed to the , the intention is this script to print
--Hello--
but it only prints ----
推荐答案
如果在命令行中使用
/property:"H='Hello'"
您可以简单地使用
System.Console.WriteLine("--"+$(H)+"--");
不需要<ParameterGroup />
块
这篇关于分配从MSBuild中的属性获取的参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!