使用MSBuild 4.0,传递要从MSBuild任务在c#项目文件中扩展的属性名,如何? [英] Using MSBuild 4.0, passing property name to be expanded in c# project file from MSBuild task, how?

查看:110
本文介绍了使用MSBuild 4.0,传递要从MSBuild任务在c#项目文件中扩展的属性名,如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为CI流程创建了一个MSBuild脚本,在此脚本中,我使用MSBuild任务来编译解决方案:

I created a MSBuild script for our CI process and in this script I use a MSBuild task to compile the solution:

<PropertyGroup>
    <MyOutPath>Output</MyOutPath>
</PropertyGroup>

<MSBuild
    Projects="MySolution.sln"
    Targets="Clean;Rebuild"
    Properties="OutputPath=$(MyOutPath)\%24(AssemblyName)">
</MSBuild>

我希望c#项目文件使用输出路径,例如

I want the c# project files to use an output path like

  • 项目MyAssemblyName1的
  • Output \ MyAssemblyName1
  • 项目MyAssemblyName2的Output \ MyAssemblyName2

AssemblyName属性来自C#项目文件,我希望在构建项目时在OutputPath属性中对其进行扩展.

The AssemblyName property is from the C# project file and I want it to be expanded in the OutputPath property when building the project.

现在,%24(AssemblyName)只是在文件系统上生成Output \ $(AssemblyName),这不是我想要的.

Right now, %24(AssemblyName) just produce Output\$(AssemblyName) on the filesystem which is not what I want.

毫不奇怪,使用$(AssemblyName)可以在父" MSBuild文件中扩展为空.

Not surprisingly, using $(AssemblyName) expands to nothing in the "parent" MSBuild file.

是否有什么方法可以稍后在目标项目文件中推迟AssemblyName属性的解析?

Is there any way to defer the resolution of the AssemblyName property later in the target project file?

此外,我不想修改.csproj文件,因为我希望从CI系统获得的影响最小.

Also, I do not want to modify the .csproj file as I want the least impact from the CI system.

推荐答案

您可以使用

如果需要导入.sln解决方案文件的内容,则首先必须

If you need to import the contents of a .sln solution file, first you'll have to convert it to an MSBuild project file by setting the MSBuildEmitSolution environment variable to 1 and run MSBuild on the solution file. This will generate a MySolution.sln.proj file, which you can then import into your script like described before:

<SetEnv Name="MSBuildEmitSolution" Value="1" />
<MSBuild Projects="MySolution.sln" Targets="Build" />
<Import Project="MySolution.sln.proj" />

这篇关于使用MSBuild 4.0,传递要从MSBuild任务在c#项目文件中扩展的属性名,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆