Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build .csproj with MSBuild without project reference

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?

like image 301
James Hart Avatar asked May 05 '14 07:05

James Hart


People also ask

Can a Visual Studio be complied with MSBuild without opening Visual Studio?

To install MSBuild on a system that doesn't have Visual Studio, go to Build Tools for Visual Studio 2019, or install the . NET SDK. If you have Visual Studio, then you already have MSBuild installed.

How do I run MSBuild manually?

To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.

Is it possible to build an application on a system if the MSBuild is not installed?

Is it possible to build an application on a system if the MSBuild is not installed? If so, How? Yes, it is actually possible because the MSBuild doesn't depend on the Visual Studio of its operations. Users simply need to install the msbuild.exe file for this.


1 Answers

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.

like image 97
stijn Avatar answered Oct 18 '22 23:10

stijn