This article is a mirror article of machine translation, please click here to jump to the original article.

View: 55049|Reply: 0

[Source] The difference between the Roslyn MSBuild compiler

[Copy link]
Posted on 3/21/2021 11:55:39 AM | | | |
MSBuild: The Microsoft Build Engine is a platform for building applications. This engine, also known as MSBuild, provides an XML schema for project files that controls how the build platform handles and builds software. Visual Studio uses MSBuild, but MSBuild doesn't depend on Visual Studio. By calling msbuild.exe in a project or solution file, you can schedule and build products in an environment without Visual Studio installed.

Introduce:The hyperlink login is visible.

Barabala said so much, as can be seen from the name, he is the compiler of Microsoft, that is, programming projects into executable programs, etc.

Used before, modify the code using txt notepad, recompile with msbuild, as follows:

Debugging .NET programs with Notepad at home on a computer for ten years
https://www.itsvse.com/thread-9419-1-1.html

Roslynis an open-source .NET compiler from Microsoft Corporation. The compiler supports C# and Visual Basic code compilation and provides rich code analysis APIs.
We try to create a new one.NET framework 4.6project, using VS 2019 will generate the MSBuild Project Generate Output Detail setting normally, as shown in the image below:



Right-click on the item to try to regenerate, as shown below:



1>------ All rebuilds have been initiated: Project: ConsoleApp1, Configuration: Debug Any CPU ------
1> The start time is 2021/3/21 11:38:08.
1>GenerateBindingRedirects:
1> There are no suggested binding redirects in ResolveAssemblyReferences.
1>GenerateTargetFrameworkMonikerAttribute:
1> is skipping the target "GenerateTargetFrameworkMonikerAttribute" because all output files are up to date relative to the input files.
1>CoreCompile:
1>  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702,2008 /fullpaths /nostdlib+ /platform: anycpu32bitpreferred /errorreport:prompt /warn:4 /define:DEBUG; TRACE /errorendlocation /preferreduilang:zh-CN /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\. NETFramework\v4.6\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\. NETFramework\v4.6\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\. NETFramework\v4.6\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\. NETFramework\v4.6\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\. NETFramework\v4.6\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\. NETFramework\v4.6\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\. NETFramework\v4.6\System.Net.Http.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\. NETFramework\v4.6\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\. NETFramework\v4.6\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\ConsoleApp1.exe /subsystemversion:6.00 /target:exe /utf8output / deterministic+ /langversion:7.3 Program.cs Properties\AssemblyInfo.cs "obj\Debug\. NETFramework,Version=v4.6.AssemblyAttributes.cs"
1> Use shared compilation for compilers from the back column directory: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn
1>_CopyAppConfigFile:
1> Copying files from "C:\Users\itsvse_nuc\source\repos\ConsoleApp1\ConsoleApp1\App.config" to "C:\Users\itsvse_nuc\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\ ConsoleApp1.exe.config”。
1>CopyFilesToOutputDirectory:
1> Copying files from "C:\Users\itsvse_nuc\source\repos\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.exe" to "C:\Users\itsvse_nuc\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\ ConsoleApp1.exe”。
1>  ConsoleApp1 -> C:\Users\itsvse_nuc\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\ConsoleApp1.exe
1> Copying files from "C:\Users\itsvse_nuc\source\repos\ConsoleApp1\ConsoleApp1\obj\Debug\ConsoleApp1.pdb" to "C:\Users\itsvse_nuc\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\ ConsoleApp1.pdb”。
1>
1> has been successfully generated.
1> 0 warnings
1> 0 errors
1>
1> Elapsed Time 00:00:00.66
========== Regenerate all: 1 succeeds, 0 fails, and 0 ========== skipped

Downloaded from other articles on the Internet, for reference only:


The .NET Framework 4.0's built-in MSBuild doesn't recognize C# 6.0 syntax features.

"MSBuild" => msbuild.exe, "Roslyn" => csc.exe

MSbuild is Visual Studio's build system. It calls the C# compiler to compile the C# project. Roslyn is a C# compiler (and VB compiler). Therefore, msbuild uses Roslyn.

However, Roslyn contains more than just a compiler. It also includes a VS plugin that gives you IDE features (completion lists, colors, code fixes, etc.).

In addition, Roslyn is an API for analyzing source code, which you can use in your own applications. For the last case, there is an API called MSBuildWorkspace that can be used to open a project or solution for analysis. This workspace uses MSBuild to find out all parts of a project and solution. Therefore, this part of Roslin uses MSBuild.


Summary:

My own understanding is that MSBuild is a collection of Microsoft compilers, and he may not be responsible for compiling the generation, but he will help us call Roslyn to compile the c# code. He can also compile code in other languages and then call other corresponding compilers.

For compiling C# projects, MSBuild is the decision-maker and Roslyn is the executor.





Previous:ASP.NET Core (VI) DI manually obtains the method of injecting objects
Next:.NET/C# Emit dynamically generates assemblies
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com