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
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:
The targets file is located in the .NET Framework directory (
C:\windows\Microsoft.NET\Framework\v3.5 or v4.0.30319).