How to build visual studio solution file .sln command line with selected project

visual studio 2010

I have .sln file which has around 352 projects.
I have created batch file below
"C:/Windows/Microsoft.NET/Framework/v4.0.30319/msbuild.exe myproj.sln /nologo /t:Build /p:Configuration="Debug" /property:Platform="Win32"
pause"

But this builds all the projects from solution. I have configured "Configuration Manager" to unselect unwanted projects or unload project and used above batch file to build but that did not serve the purpose.

I have searched MSBuild options but could not find exact answer.

Can anyone help me in this ?

Best Answer

MSbuild accepts project name as part of "target" (/t) specification:

MSBuild /nologo /t:ProjectName:Build SolutionFile.sln

Or, if your project does not depend on other projects in solution, directly use project file with MSBuild:

MSBuild /nologo /t:Build ProjectFile.vcxproj

This trick works with Visual Studio 2010, 2012, 2013, 2015, 2017 and with latest MSVS 2019.