Pregunta

I have spent the last 2 days trying to figure out how to use the SvnInfo task in the MSBuild Community Tasks pack relatively. It works on my machine because I used the installer. Though surely I should be able to make it work with a relative path. If I don't install the the pack on the CI server I should be able to store the pack in svn and when the ci server gets all the code to build it, the build script that I have written seems to try to reference the tasks and dlls etc off the c: drive where it would normally be installed but doesn't exist. I'm not sure why. Even if I use a property to refer to the relative task and then reference the property throughout the task it still seems to error out.

I want to retrieve the svn revision number from subversion (our svn) and then update the assembly revision number. So that we can tie what was implemented back to what changeset was pulled for that release. What little documentation I could find for the msbuild community pack said that I should use the client only but the only one that I could find to use was slik svn. It seems to work locally but somehow that also feels wrong ... should I stick with the same flavor of svn.

IF anyone has any suggestions or improvements or links that they were able to find that I could not ... it would be much appreciated.

<?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) /xml=@(TestResults)" />
    <Message Text="UNIT TESTS HAVE COMPLETED." 
         Importance="high" />
  </Target>

</Project>
¿Fue útil?

Solución

To reference an MSBuild Community Task with a relative path to the assembly, try adding this at the top:

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

The Import brings in all the UsingTask's which point to an assembly at $(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.dll where MSBuildCommunityTasksPath is relative to the `.Targets' project file.

Otros consejos

I have following directory structure on source control:

\BuildScripts\Bin\
\BuildScripts\Scripts\

I installed MsBuild Community Tasks on my local PC and I moved all relevant files into \BuildScripts\Bin\ folder. In the scripts I'm using relative path to MSBuild.Community.Tasks.Targets file.

<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>

On the build server I get BuildScripts folder from the source control before build. Then I execute my scripts in BuildScripts\Scripts folder and it is working. This is also working locally for other developers in our team without installing MsBuild Community tasks.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top