简体   繁体   English

如何使用msbuild首先构建依赖项目

[英]How to build dependent project first with msbuild

I have just started looking into msbuild, because I want to make my own build scripts. 我刚开始研究msbuild,因为我想制作自己的构建脚本。 For now I am able to create build scripts that compiles only one project, but how do I handle dependencies? 现在我能够创建只编译一个项目的构建脚本,但是如何处理依赖项呢?

For example what if I have two projects that gets build with these two msbuild scripts? 例如,如果我有两个使用这两个msbuild脚本构建的项目怎么办?

  1. projectA.xml projectA.xml
  2. projectB.xml projectB.xml

How do I tell msbuild that when I am executing projectB.xml that it should first execute projectA.xml? 我怎么告诉msbuild我在执行projectB.xml时应该首先执行projectA.xml?

I have googled alot on this, but it does not seem to get anything that a starter like me understands. 我已经在谷歌搜索了很多,但它似乎没有任何像我这样的初学者理解的东西。 I would be more than happy with a link to an article describing this, or maybe just a small code example. 我会对描述这篇文章的链接感到高兴,或者只是一个小代码示例。

The reason why I want this control is because of a library I am building. 我想要这个控件的原因是因为我正在构建一个库。 The library consists of several projects. 该图书馆由几个项目组成。 A developer should be able to pull the source code for the library down and build only the libraries that he wants. 开发人员应该能够提取库的源代码并仅构建他想要的库。

Actually I want to be able to build .net modules from the different projects. 实际上我希望能够从不同的项目中构建.net模块。 That is why I want to be able to run a customized msbuild script. 这就是为什么我希望能够运行自定义的msbuild脚本。

If you create a solution with the two projects you can target the .sln file with msbuild, rather than directly building the projects, it should take care of project dependencies :) 如果您使用这两个项目创建一个解决方案,您可以使用msbuild定位.sln文件,而不是直接构建项目,它应该处理项目依赖项:)

But that's if you're using standard .csproj projects... 但是如果你使用的是标准的.csproj项目......

Ok I looked at a project I'm working on, and it's like this: 好的,我看了一个我正在研究的项目,它是这样的:

<ItemGroup>
   <ProjectReference Include="..\SomeFolder\SomeProject.csproj">
      <Project>{1A94B405-2D01-4A09-90D5-A5B31180A03B}</Project>
      <Name>SomeProjectNamespace</Name>
   </ProjectReference>
</ItemGroup>

And here's an MSDN page about references. 这是一个关于参考的MSDN页面 Scroll down till you find ProjectReference... 向下滚动,直到找到ProjectReference ...

I setup my build scripts so that I have a few common targets that do not do anything, but use DependsOnTargets to setup project dependencies and run the build. 我设置了我的构建脚本,以便我有一些不做任何事情的常见目标,但是使用DependsOnTargets来设置项目依赖项并运行构建。

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

  <!-- ************************************************************************************************ -->
  <!-- Targets that run the builds -->
  <!-- ************************************************************************************************ -->
  <Target Name="AutoBuild" DependsOnTargets="BuildProject1;BuildProject2;BuildInstallers">
    <OnError ExecuteTargets="NotifyFailure" />
  </Target>
  <Target Name="FullCompile" DependsOnTargets="BuildProject1;BuildProject2">
    <OnError ExecuteTargets="NotifyFailure" />
  </Target>

  <!-- Build Project 1 -->
  <Target Name="BuildProject1">
    <!-- Use MSBuild task and point it to build project1.csproj, project1.sln or whatever your projects is -->
  </Target>

  <!-- Build Project 2 -->
  <Target Name="BuildProject2">
    <!-- Use MSBuild task and point it to build project2.csproj, project2.sln or whatever your projects is -->
  </Target>

  <Target Name="BuildInstallers">
    <!-- Whatever logic you have for building installers -->
  </Target>

</Project>

In MSBuild issue #2887 a similar situation is discussed. MSBuild问题#2887中,讨论了类似的情况。 The thread also reveals a link to official ProjectReference Protocol . 该线程还显示了官方ProjectReference协议的链接。

You dont need to build using the sln. 你不需要使用sln构建。 If you use project references in your csproj then the dependency order is taken care of by MSBuild. 如果在csproj中使用项目引用,则依赖顺序由MSBuild处理。 Try it. 试试吧。 Automajically. Automajically。 You do not need to sort the dependency order in your msbuild script. 您不需要在msbuild脚本中对依赖顺序进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 MSBuild 构建项目? - How to build project using MSBuild? MSbuild构建订单问题 - 首先构建预先构建步骤或首先依赖项目 - MSbuild build order issue - pre-build steps first or dependent projects first MSBuild 在 _CopyOutOfDateSourceItemsToOutputDirectory 期间复制依赖项目文件 - MSBuild copies dependent project files during _CopyOutOfDateSourceItemsToOutputDirectory MSBuild:如何根据构建源项目的名称有条件地在.csproj文件中导入另一个项目? - MSBuild: How to conditionally import another project in a .csproj file based on the name of build-originated project? 我可以在 VS 中构建这个项目,但不能用 msbuild - I can build this project in VS but not with msbuild 使用MSBuild构建.csproj而不使用项目引用 - Build .csproj with MSBuild without project reference 以编程方式使用 MSBuild 构建项目 - NuGetSdkResolver 或 InvalidProjectFileException 错误 - Build Project with MSBuild programmatically - NuGetSdkResolver or InvalidProjectFileException error 使用MSBuild for Build解决方案包括InstallShield ProjecT - Using MSBuild for Build solution include InstallShield ProjecT 在Project.Build的程序中使用2013 msbuild - Using 2013 msbuild in program with Project.Build 如何使用 MSBuild 构建文件 - How to build the file using MSBuild
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM