在MSBuild Project文件中,我想采用以下变量:
$(MSBuildProjectDirectory)
等于:
c:\projects\myproject\branches\changenumber\soapservice
并创建此变量:
$(MSBuildProjectDirectoryName)
将其设置为:
changenumber
我想在MSBuild项目文件中执行以下操作:
<PropertyGroup>
<LinqToXsdBinDir Condition="'$(LinqToXsdBinDir)' == ''">$(SolutionDir)..\LinqToXsd</LinqToXsdBinDir>
<MSBuildProjectParentDirectoryName Condition="'$(MSBuildProjectDirectoryName)' == ''">Path.GetDirectoryName(Path.GetDirectory($(MSBuildProjectDirectory)))</MSBuildProjectParentDirectoryName>
***SNIP***
</PropertyGroup>
***SNIP***
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<IISUrl>http://localhost/ThisSoft/$(MSBuildProjectParentDirectoryName)/LayerName</IISUrl>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
如何将MSBuild变量设置为等效于:
string MSBuildProjectDirectory = Path.GetFileName(Path.GetDirectoryName(bob));
答案 0 :(得分:1)
首先,您获取一个公共分支属性文件,例如“Branch.Props”,然后将其放在c:\ projects \ myproject \ branches \ changenumber \ branch.props中。 然后,将常用的msbuild属性添加到此文件中,例如:
<PropertyGroup>
<LinqToXsdBinDir Condition="'$(LinqToXsdBinDir)' == ''">$(SolutionDir)..\LinqToXsd</LinqToXsdBinDir>
</PropertyGroup>
然后,因为您了解MsBuild保留名称,所以在所有解决方案项目中都创建了一个没有“MsBuild”前缀的新属性:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BranchRoot>$([MSBuild]::GetDirectoryNameOfFileAbove( $(MSBuildProjectDirectory) ,Branch.Props))</BranchRoot>
</PropertyGroup>
<Import Project="$(BranchRoot)\Branch.props" />
...