7
votes

When writing an MSBuild file from scratch, is it possible to build .csproj files directly without a reference to the solution they're a member of? Introductory guides like this one often explain how to compile individual .cs files or build a .csproj directly from the command line.

For example, command line MSBuild without a .sln reference:

msbuild helloworld.csproj /t:Build /verbosity:detailed

Or a .csproj given a .sln:

<MSBuild
  Projects="mysolution.sln"
  Targets="My_Project_File"
  Properties="Configuration=$(Configuration);Platform=$(Platform)"
  ContinueOnError="false" />

I haven't found any references mentioning building the .csproj within an MSBuild file without a .sln. Is there a way and I'm just missing something?

1
Have you just tried <MSBuild Projects="my_project.csproj" Targets="Build" /> ?stijn
Does your individual project reference any other projects.."by project" ?granadaCoder
@stijn that worked. Thank you very much. You should add it as an answer, too.James Hart
1. Re: "without a reference to the solution they're a member of". In case you didn't know, a project is an unknowing member of zero or more solutions (which could be in any place in the file system). 2. If you're interested, MSBuild can build a Visual Studio solution file by converting it on the fly to a temporary MSBuild project file.Tom Blodget

1 Answers

7
votes

There is nothing wrong whatsoever with building csproj files without a solution:

<MSBuild Projects="my_project.csproj" Targets="Build" />

moreover, when you build a solution with Visual Studio what it actually does internally is convert the solution file to an msbuild script that contains a line like the above to build the projects.