Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does MSBuild decide whether it needs to rebuild a C# library or not?

Tags:

How does MSBuild decide whether it needs to rebuild a library (that is, invoke csc), or not, when it is run against a C# project file?

I imagine (but want to confirm):

  • If there's no output directory, rebuild (duh :) )
  • If a C# file has changed, rebuild
  • If an included file marked copy-always has changed, rebuild
    • Or is it smart enough to not rebuild, but just copy the file to the existing output?
  • If an included file marked copy-if-newer has changed, rebuild
    • Same question as above
like image 547
Peter Mounce Avatar asked Feb 22 '11 17:02

Peter Mounce


People also ask

How does MSBuild create solution?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.

What does MSBuild command do?

Builds the targets in the project file that you specify. If you don't specify a project file, MSBuild searches the current working directory for a file name extension that ends in proj and uses that file. You can also specify a Visual Studio solution file for this argument.

What is the difference between MSBuild and Visual Studio build?

Visual Studio determines the build order and calls into MSBuild separately (as needed), all completely under Visual Studio's control. Another difference arises when MSBuild is invoked with a solution file, MSBuild parses the solution file, creates a standard XML input file, evaluates it, and executes it as a project.

What does rebuild solution do in Visual Studio?

Rebuild Solution : Deletes all compiled files and Compiles them again regardless of whether or not the code has changed.


1 Answers

If you look in Microsoft.CSharp.targets (the MSBuild file for compiling C# projects) the CoreCompile target has a set of Inputs and Outputs defined. These are used to do the dependency checking to see if CoreCompile needs to run. The list of inputs include the C# files, resource files, application icon, strong name key file, and other custom inputs you can define.

If you have a solution and run MSBuild on it with diagnostic logging enabled (/v:diag command line parameter), you might see this message if the outputs are up to date:

Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.

The targets file is located in the .NET Framework directory (C:\windows\Microsoft.NET\Framework\v3.5 or v4.0.30319).

like image 199
Brian Walker Avatar answered Sep 18 '22 07:09

Brian Walker