2014-05-14 48 views
0

我需要爲一個屬性讀取xml文件,並且該屬性應該在Next teamcity構建中使用。 現在我擁有的配置如何將參數從MsBuild傳遞到TeamCity

<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
<PropertyGroup> 
    <MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\.build</MSBuildCommunityTasksPath> 
    <ExtensionTasksPath>$(MSBuildProjectDirectory)\.build\</ExtensionTasksPath> 
</PropertyGroup> 

<Import Project="$(MSBuildCommunityTasksPath)\MSBuild.ExtensionPack.tasks"/> 
<Target Name="SetValue"> 

    <!-- ReadAttribute --> 
    <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadElementText" File="my.config" XPath="/configuration/version"> 
     <Output PropertyName="build.PackageVersion" TaskParameter="Value"/> 
    </MSBuild.ExtensionPack.Xml.XmlFile> 
    <Message Text="SourceProtocol = $(build.PackageVersion)"/> 
</Target> 

但變量packageversion仍然是空的TeamCity的。

回答

1

它的價值build.PackageVersion的名稱選擇是無效的msbuild不像期間。

你把你的路徑和擴展包與$(MSBuildCommunityTasksPath)\MSBuild.ExtensionPack.tasks混合在一起。應該$(ExtensionTasksPath)\MSBuild.ExtensionPack.tasks.

所以我測試了它在當地 -

<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 


    <UsingTask AssemblyFile="C:\Program Files (x86)\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.dll" TaskName="MSBuild.ExtensionPack.Xml.XmlFile"/> 
<Target Name="Build"> 
    <!-- ReadAttribute --> 
    <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadElementText" File=".\my.config" XPath="/configuration/version"> 
     <Output PropertyName="PackageVersion" TaskParameter="Value"/> 
    </MSBuild.ExtensionPack.Xml.XmlFile> 
    <Message Text="SourceProtocol = $(PackageVersion)"/> 
</Target> 

</Project> 

和工作原理。

+0

安全問題是一樣的如何從msbuild返回值;) –