简体   繁体   English

从命令行在解决方案中仅构建一个项目

[英]Build only one project in a solution from command line

I have a solution with lots of solution folders with lots of c# projects inside them.我有一个解决方案,里面有很多解决方案文件夹,里面有很多 c# 项目。

How do I build/rebuild only one of those projects from command line?如何从命令行仅构建/重建这些项目之一?

I guess there's some way to do it using msbuild but I don't know anything about msbuild.我想有一些方法可以使用msbuild来做到这一点,但我对 msbuild 一无所知。

Thanks!谢谢!

Given a solution file with projects in it, and you want to build / rebuild one project.给定一个包含项目的解决方案文件,并且您想要构建/重建一个项目。

This webpage on MSDN lists exactly what you have to do: MSDN 上的此网页准确列出了您必须执行的操作:

http://msdn.microsoft.com/en-us/library/ms171486.aspx http://msdn.microsoft.com/en-us/library/ms171486.aspx

So given a solution file mysolution.sln with projects:所以给定一个带有项目的解决方案文件 mysolution.sln:

  • foo.vcxproj foo.vcxproj
  • bar.vcxproj bar.vcxproj
  • baz.vcxproj baz.vcxproj

where they all depend on each other in bottom to top order.他们都从下到上相互依赖。 So that baz is most independent, bar depends on baz and foo depends on bar .所以baz是最独立的, bar依赖于bazfoo依赖于bar

If you want to build foo then you do:如果你想建立 foo 那么你做:

MSBuild mysolution.sln /target:foo

The other answers here didn't account about dependencies.这里的其他答案没有考虑依赖项。 Sure msbuild.exe will build a single project file (ie foo.vcxproj), but it would fail if bar and baz were not built yet.当然 msbuild.exe 将构建单个项目文件(即 foo.vcxproj),但如果 bar 和 baz 尚未构建,它将失败。 In order to build multiple projects and get the independent projects built first you have to pass in the solution file (After all the OP did mention this was part of a solution file).为了构建多个项目并首先构建独立的项目,您必须传入解决方案文件(毕竟 OP 确实提到这是解决方案文件的一部分)。 Then pass in the project name and a target delimited by a colon.然后传入项目名称和以冒号分隔的目标。

MSBuild mysolution.sln /target:foo:Rebuild

Big assumption here.这里的假设很大。 I'm assuming that the project name $(ProjectName) matches that of the file name.我假设项目名称 $(ProjectName) 与文件名匹配。

Edit (from comment ) : If you happen to have dots (.) in the project name, you'll need to replace them with an underscore (_).编辑(来自评论 :如果项目名称中碰巧有点 (.),则需要将它们替换为下划线 (_)。

You can simply call msbuild and pass it the .csproj/.vbproj project file that you want to build, and it will do only that one.您可以简单地调用msbuild并将您想要构建的 .csproj/.vbproj 项目文件传递给它,它只会执行那个。

So something like:所以像:

cd \MySolution
msbuild .\Project1\Project1.csproj

You can consult this reference to learn more about using MSBuild from the command-line.您可以查阅参考资料以了解有关从命令行使用 MSBuild 的更多信息。 Here is an example of what you need:这是您需要的示例:

MSBuild.exe MyProject.proj /t:rebuild

Posting as information to future seekers作为信息发布给未来的求职者

set MSBuildEmitSolution=1设置 MSBuildEmitSolution=1

https://stackoverflow.com/a/40372894/826862 https://stackoverflow.com/a/40372894/826862

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

相关问题 可以从命令行编译和测试解决方案的构建脚本 - a build script that can compile and test the solution from the command line 通过命令行仅构建VS Setup项目 - Build only the VS Setup project via command line dotnet 仅从 VSTS 中的解决方案发布一个项目 - dotnet publish only one project from the solution in VSTS 从命令行在2017 Visual Studio中构建项目? - Build project in 2017 Visual Studio from the command line? 从帮助程序项目Visual Studio多个项目解决方案中获取命令行参数 - Getting command line arguments from the helper project visual studio multiple project solution 在 Visual Studio Online Build Definition 中从具有多个 Web 项目的解决方案构建一个 Web 项目 - Build one web project from a Solution with multiple web projects in Visual Studio Online Build Definition 命令行生成解决方案与Visual Studio 2012生成 - Command line build solution vs Visual Studio 2012 build 从VSIX命令启动解决方案构建 - Start solution build from VSIX command 通过命令行构建 Visual Studio 项目 - Build Visual Studio project through the command line 在命令行上生成解决方案文件(从头开始创建新解决方案)? - generate solution file on command line (create new solution from scratch)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM