MSBuild不评估构建中的参数

时间:2013-05-23 23:12:13

标签: msbuild

我在Visual Studio中有一个自定义项目类型,其中包含以下内容:

 <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <TestNode>$(Configuration)</TestNode>

我打电话的时候:

msbuild mysolution.sln /p:Configuration=Release

正确调用属性组,但TestNode不包含“已发布”但“$(配置)”......有什么想法吗?

2 个答案:

答案 0 :(得分:0)

尝试使用引用它的引号包装属性:“$(Configuration)”

    <Target Name="Target1">
    <PropertyGroup>
        <Configuration>release</Configuration>
    </PropertyGroup>
    <Message Text="this is a test $(Configuration)" Importance="high" />
</Target>

输出:这是测试版本

答案 1 :(得分:0)

'为我工作'

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <SomeData>$(Configuration)</SomeData>
  </PropertyGroup>

  <Target Name="Bobby">
    <Message Text="Value of SomeData is: $(SomeData)" />
  </Target>
</Project>

然后运行

C:\Users\mvine\Desktop>msbuild Test.fooproj /p:Configuration=Release /t:Bobby
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.18033]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 24/05/2013 10:06:14.
Project "C:\Users\mvine\Desktop\Test.fooproj" on node 1 (Bobby target(s)).
Bobby:
  Value of SomeData is: Release
Done Building Project "C:\Users\mvine\Desktop\Test.fooproj" (Bobby target(s)).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.03

也许这个答案会帮助你正确理解你的语法,如果没有添加一个自包含的repro(并回复这个答案,我会收到通知),我会看看。