Using MSBuild 4.0, passing property name to be expanded in c# project file from MSBuild task, how?
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>
I want the c# project files to use an output path like
- Output\MyAssemblyName1 for开发者_Python百科 the project MyAssemblyName1
- Output\MyAssemblyName2 for the project MyAssemblyName2
The AssemblyName property is from the C# project file and I want it to be expanded in the OutputPath property when building the project.
Right now, %24(AssemblyName) just produce Output\$(AssemblyName) on the filesystem which is not what I want.
Not surprisingly, using $(AssemblyName) expands to nothing in the "parent" MSBuild file.
Is there any way to defer the resolution of the AssemblyName property later in the target project file?
Also, I do not want to modify the .csproj file as I want the least impact from the CI system.
You could import the .csproj
project file directly into your MSBuild script using the Import element. This way you could reference the AssemblyName
property directly:
<Import Project="MyProject.csproj" />
<Message Text="The assembly name is $(AssemblyName)" />
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" />
精彩评论