How to run a clean build for a particular project from a solution in visual studio

こ雲淡風輕ζ 提交于 2020-12-24 03:09:06

问题


Suppose I need to build a whole solution (which has multiple projects) in command line, is it possible to run a clean build for a particular projects and run an incremental build for the rest of the project?

Thanks.


回答1:


Use msbuild and pass the Clean and Rebuild targets:

msbuild path\to\solution\yoursolution.sln /t:Clean;Rebuild

Or if you only want to rebuild a single project:

msbuild path\to\project\yourproject.csproj /t:Clean;Rebuild

msbuild is available in the Windows SDK or the Visual Studio Command prompt.




回答2:


MSBuild.exe MultiProjectSolution.sln /t:"ProjectName:clean"

Will clean only the specified project in your solution.




回答3:


Cleaning up specific projects:

msbuild MyProjectFile1 /t:Clean
msbuild MyProjectFile2 /t:Clean
...

This has to be repeated for all projects you need to clean, because MSBuild only accepts single project on command line.

Build whole solution incrementally:

msbuild MySolutionFile

Note, that this will build default configuration/platform for the projects and solution, which is often Debug/AnyCPU or Debug/Win32. If you want specific configuration/platform, you have to add parameters like this: /p:Configuration=Release /p:Platform=x64 to every msbuild command line.




回答4:


Just a small refinement for using in PowerShell:

pathTo\MSBuild.exe pathTo\solutionfile.sln /target:"clean;Build"

Source For Different Target



来源:https://stackoverflow.com/questions/14367582/how-to-run-a-clean-build-for-a-particular-project-from-a-solution-in-visual-stud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!