[英]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:
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
依赖于baz
而foo
依赖于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
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.