通过相对路径引用 msbuild 社区任务

发布于 2024-12-18 02:10:07 字数 4132 浏览 3 评论 0原文

在过去的两天里,我一直在尝试弄清楚如何相对地使用 MSBuild 社区任务包中的 SvnInfo 任务。它可以在我的机器上运行,因为我使用了安装程序。虽然我肯定应该能够让它以相对路径工作。如果我不在 CI 服务器上安装包,我应该能够将包存储在 svn 中,当 ci 服务器获取构建它的所有代码时,我编写的构建脚本似乎会尝试引用任务和 dll 等位于通常安装但不存在的 c: 驱动器上。我不知道为什么。即使我使用属性来引用相关任务,然后在整个任务中引用该属性,它似乎仍然会出错。

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

</Project>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往昔成烟 2024-12-25 02:10:07

要引用带有程序集相对路径MSBuild Community Task,请尝试将其添加到顶部:

<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' 项目文件。

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.

养猫人 2024-12-25 02:10:07

我在源代码管理上有以下目录结构:

\BuildScripts\Bin\
\BuildScripts\Scripts\

我在本地 PC 上安装了 MsBuild Community Tasks,并将所有相关文件移至 \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 Community 任务。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文