2011-11-24 70 views
2

我花了最近2天試圖找出如何相對使用MSBuild社區任務包中的SvnInfo任務。它在我的機器上工作,因爲我使用了安裝程序。雖然我應該能夠使它與相對路徑一起工作。如果我不在CI服務器上安裝這個包,我應該可以將包存儲在svn中,並且當ci服務器獲取所有代碼來構建它時,我編寫的構建腳本似乎試圖引用任務和dll等關閉c:驅動器,它通常會安裝但不存在。我不知道爲什麼。即使我使用屬性來引用相關任務,然後在整個任務中引用屬性,它仍似乎錯誤。通過相對路徑引用msbuild社區任務

我想從subversion(我們的svn)中檢索svn版本號,然後更新程序集版本號。這樣我們可以將實現的內容與該版本的變更集相關聯。我能找到的關於msbuild社區包的小文檔說我只能使用客戶端,但唯一能找到的是slik svn。它似乎在本地工作,但不知何故,這也感覺不對......應堅持與svn相同的味道。

如果任何人有任何建議或改進或鏈接,他們能夠發現我不能......這將不勝感激。

<?xml version="1.0" encoding="utf-8"?> 
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 
    ToolsVersion="4.0"> 

    <PropertyGroup> 
    <RevisionNumber Condition=" '$(RevisionNumber)' == '' ">x</RevisionNumber> 
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 
    </PropertyGroup> 


    <!-- 1 --> 
    <Import Project=".\ThirdParty\Tools\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" /> 
    <UsingTask AssemblyFile=".\ThirdParty\Tools\MyMSBuildExtensions\BuildTasks.MSBuildTaks.dll" 
     TaskName="BuildTasks.MSBuildTasks.AssemblyInfoReader" /> 
    <UsingTask AssemblyFile="$(MSBuildCommunityTasksPath)MSBuild.Community.Tasks.dll" 
     TaskName="MSBuild.Community.Tasks.Subversion.SvnInfo" /> 


    <ItemGroup> 
    <!-- Required here in order to use the outDir syntax in the compile target - useage "@(BuildArtifacts)" --> 
    <BuildArtifacts Include=".\buildartifacts\" /> 
    <SolutionFile Include=".\OnlineSales.sln" /> 
    </ItemGroup> 

    <ItemGroup> 
    <NUnit Include=".\ThirdParty\Tools\NUnit\nunit-console.exe" /> 
    <TestAssembly Include=".\buildArtifacts\OnlineSales.Tests.dll" /> 
    <TestResults Include=".\buildartifacts\TestResults.xml" /> 
    </ItemGroup> 


    <Target Name="Clean" > 
    <RemoveDir Directories="@(BuildArtifacts)" /> 
    <Message Text="CLEAN COMPLETED." Importance="high" /> 
    </Target> 

    <Target Name="Init" DependsOnTargets="Clean"> 
    <MakeDir Directories="@(BuildArtifacts)" /> 
    <Message Text="BUILDARTIFACTS DIRECTORY HAS BEEN CREATED." Importance="high" /> 
    </Target> 

    <Target Name="Compile" DependsOnTargets="Init"> 
    <SvnInfo RepositoryPath="https://cnfglfcdv01/svn/Primary/Users/kdonde/" 
      UserName="user" 
      Password="password" 
      ToolPath=".\ThirdParty\Tools\SlikSvn" > 

     <!-- 2 --> 
     <Output TaskParameter="Revision" PropertyName="RevisionNumber" /> 
    </SvnInfo> 
    <Message Text="SVN INFO HAS BEEN EXECUTED." Importance="high" /> 
    <Message Text="$(RevisionNumber) :================" Importance="high" /> 
    <Message Text="$(MSBuildCommunityTasksPath) :================" Importance="high" /> 


    <!-- 3 --> 
    <FileUpdate Files=".\Fit4Less.OnlineSales\Properties\AssemblyInfo.cs" 
      Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)" 
      ReplacementText="$1.$2.$3.$(RevisionNumber)" /> 
    <Message Text="AssemblyInfo.cs has been updated with version info." /> 

    <MSBuild Projects="@(SolutionFile)" 
     Targets="Rebuild" 
     Properties="OutDir=%(BuildArtifacts.FullPath);Configuration=$(Configuration)" /> 
    <Message Text="BUILD HAS COMPLETED." 
     Importance="high" /> 
    </Target> 


    <!-- 4 --> 
    <Target Name="Deploy" 
     DependsOnTargets="Compile"> 
    <AssemblyInfoReader Path=".\OnlineSales\Properties\AssemblyInfo.cs" 
        Property="AssemblyVersion" > 
     <Output TaskParameter="Value" 
      ItemName="Version" /> 
    </AssemblyInfoReader> 
    <Message Text="ASSEMBLYINFOREADER HAS COMPLETED." 
     Importance="high" /> 
    </Target> 



    <Target Name="Test" DependsOnTargets ="Compile"> 
    <Exec Command="@(NUnit) @(TestAssembly) /[email protected](TestResults)" /> 
    <Message Text="UNIT TESTS HAVE COMPLETED." 
     Importance="high" /> 
    </Target> 

</Project> 
+0

對於指向安裝的任務程序集('$(MSBuildCommunityTasksPath)MSBuild.Community.Tasks.dll')的SvnInfo,應具有與Using AssemblyInfoReader中的路徑一樣的'UsingTask'。 –

回答

4

要與相對路徑到組裝引用的MSBuild社區任務,嘗試在頂部添加此:

<PropertyGroup> 
    <MSBuildCommunityTasksPath>.</MSBuildCommunityTasksPath> 
</PropertyGroup> 
<Import Project="packages\MSBuildTasks.1.4.0.56\tools\MSBuild.Community.Tasks.Targets" /> 

Import在所有UsingTask的帶來該點到組裝在$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.dll其中MSBuildCommunityTasksPath是相對於`.Targets'項目文件。

+0

這是正確的答案。設置屬性至關重要,如果未設置,則默認按照文件MSBuild.Community.Tasks.Targets中的邏輯在C:\ Program Files中進行搜索。 –

2

我已經在源代碼控制下的目錄結構:

\BuildScripts\Bin\ 
\BuildScripts\Scripts\ 

我安裝我的本地計算機上的MSBuild社區任務,我感動了所有相關的文件到\ BuildScripts \ BIN \文件夾中。在腳本中,我正在使用MSBuild.Community.Tasks.Targets文件的相對路徑。

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> 
    <!-- Import Community Tasks --> 
    <Import Project="..\Bin\MSBuild.Community.Tasks.Targets"/> 

    <Target Name="Compile"> 
    <SvnInfo RepositoryPath="https://cnfglfcdv01/svn/Primary/Users/kdonde/" 
      UserName="user" 
      Password="password" 
      ToolPath=".\ThirdParty\Tools\SlikSvn" > 

     <Output TaskParameter="Revision" PropertyName="RevisionNumber" /> 
    </SvnInfo> 
    <Message Text="SVN INFO HAS BEEN EXECUTED." Importance="high" /> 
    <Message Text="$(RevisionNumber) :================" Importance="high" /> 
    <Message Text="$(MSBuildCommunityTasksPath) :================" Importance="high" /> 
</Target> 
</Project> 

在構建服務器上,構建之前,我從源代碼管理中獲取BuildScripts文件夾。然後我在BuildScripts \ Scripts文件夾中執行我的腳本,它正在工作。這也適用於我們團隊中其他開發人員的本地工作,無需安裝MsBuild社區任務。

+0

這不就是我在做什麼......我不明白你上面提到的與我正在做的不同嗎?有什麼不同?還是你只是確認我在做什麼應該工作? –

+0

我試圖向你展示工作樣品,它對我是如何工作的。它也應該以這種方式爲你工作。 – Ludwo