[ZZ] One of the Whidbey Series: MSBuild

xiaoxiao2021-03-06  42

There is an article similar to Ant for project compilation tools in .NET Framework 2.0: (Oriminary address: http://terry.home.sjtu.info/docview.aspx? Id = 19, Author site: http://terry.home.sjtu.info, strongly recommended !!) One of the Whidbey Series: MSBuild

Author: Terry (www.sjtu.info)

Source: Original

2005-2-21

Link: .NET Framework 2.0 Redistributable Beta 1 Link: .NET Framework 2.0 SDK Beta 1 Msbuild is the project compilation tool for .NET Framework 2.0, using MSBuild if you do not use Visual Studio whidbey, you can use MSBuild. Build a complex .NET project. By writing msbuild's makefile files (ie * Proj files), we can handle more complex programs complicated than Visual Student.Net 2005. Msbuild can be used after installation .NET Framework 2.0 SDK, start the .NET Framework SDK Command Prompt, you can use MSBuild. Unlike traditional Make or NMAKE tools, MSBuild is not a separate tool. Msbuild itself relies on .NET Framework 2.0 CLR, when performing MSBuild compiling project, will call Microsoft.Build.Engine.dll, Microsoft.Build.Framework.dll , Microsoft.Build.utilities.dll, Microsoft.Build.Tasks.dll four .NET assemblies, and some configuration files in the Framework and Schama. Msbuild's Usage Most descriptions in the SDK document, located in .NET Framework SDK Documentation / General Reference / Msbuildation. Msbuild does not provide support for the 1.1 version compiler. If the CSC task is executed, the C # compiler called .NET Framework 2.0. By writing custom MSBuild Task, we can let MSBuild execute any tasks you want to perform, as long as the task can be described in .NET language. The following is an example, in this example we created a MSBuild Task, this Task called the C # compiler in the .NET Framework 1.1 executes the compilation task of C # code. Note that the MSBuild Task itself is running in the .NET Framework 2.0 CLR, while MSBuild executes the Task's C # code compilation target is executed in the 1.1 CLR. Also, we also create this MSBuild Task by using MSBuild. Link: Engineering Info.sjtu.home.terry.tasks Source Code

Info.sjtu.home.Terry.Tasks.csc1.cs namespace info.sjtu.home.terry.tasks {public class csc1: task {private const string compiler_path @ "c: /windows/microsoft.net/framework/v1. 1.4322 / csc.exe "; .... Class Inherited from Microsoft.Build.utilities.Task, becomes MSBuild Task, performs C # compilers in V1.1.4322 via constant compiler_path. Info.Sjtu.Home.Terry.Tasks.Csc1.cs public string Sources {get {return sources;} set {sources = value;}} public string OutputAssembly {get {return outputAssembly;} set {outputAssembly = value;}} public string TargetType {get {return targetType;} set {targetType = value;}} public string Define {get {return define;} set {define = value;}} public string Doc {get {return doc;} set {doc = value ;}} public string References {get {return references;} set {references = value;}} public string AddModules {get {return addModules;} set {addModules = value;}} public string Debug {get {return debug.ToString ( );} set {debug = boolean.Parse (value);}} public string unsafe {get {return _unsafe.tostring ();} set {_unsafe = boolean.parse (value);}} msbuild By resolving * Proj file, Create a CSC1 instance and pass the settings in * Proj to these properties of CSC1, then call the Execute () method override in CSC1. In the EXECUTE method of the CSC1, the parameters of CSC.exe will be generated, and the C # compiler is started by creating System.Diagnostics.Process. Register the MSBuild Task in the .NET Framework 2.0 SDK Command Prompt:

Gacutil / I Info.sjtu.home.terry.tasks.csc1.dll also needs to register this global cache to MSBuild. Open MSBuild's task registration file, usually c: /windows/microsoft.net/framework/v2.0.40607/Microsoft.common.tasks, add a line in the Project section:

now by writing * Proj file, we can compile the original 1.1 C # engineering through MSBuild. I wrote a proj file for IMS 5.0 Beta (http://terry.home.sjtu.info/ims5.aspx):

msbuild.proj < / Target> < Target name = "clean"> The following is the case where the Debug target defined in the proj file in the above proj file is used in MSBUILD: the Proj file is easier to write, which complies with the XML specification, we can Develop an app to generate a Proj file,

转载请注明原文地址:https://www.9cbs.com/read-53443.html

New Post(0)