首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何从C#调用MSBuild

从C#调用MSBuild的方法如下:

  1. 引入Microsoft.Build.Framework和Microsoft.Build.Utilities命名空间。
代码语言:csharp
复制
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
  1. 创建一个自定义的Task类,继承自ToolTask。
代码语言:csharp
复制

public class BuildTask : ToolTask

{

代码语言:txt
复制
// 定义属性和参数
代码语言:txt
复制
[Required]
代码语言:txt
复制
public string ProjectFile { get; set; }
代码语言:txt
复制
public string Target { get; set; }
代码语言:txt
复制
public string Configuration { get; set; }
代码语言:txt
复制
public string Platform { get; set; }
代码语言:txt
复制
public bool NoLogo { get; set; }
代码语言:txt
复制
public bool NoConsoleLogger { get; set; }
代码语言:txt
复制
public bool Verbosity { get; set; }
代码语言:txt
复制
public bool MaxCpuCount { get; set; }
代码语言:txt
复制
public bool NodeReuse { get; set; }
代码语言:txt
复制
public bool DetailedSummary { get; set; }
代码语言:txt
复制
public bool IgnoreProjectExtensions { get; set; }
代码语言:txt
复制
public bool ValidateProjectFile { get; set; }
代码语言:txt
复制
public bool Restore { get; set; }
代码语言:txt
复制
public bool ConsoleLoggerParameters { get; set; }
代码语言:txt
复制
public bool DistributedFileLogger { get; set; }
代码语言:txt
复制
public bool FileLogger { get; set; }
代码语言:txt
复制
public bool FileLoggerParameters { get; set; }
代码语言:txt
复制
public bool GraphBuild { get; set; }
代码语言:txt
复制
public bool Interactive { get; set; }
代码语言:txt
复制
public bool IsolateProjects { get; set; }
代码语言:txt
复制
public bool LogCommand { get; set; }
代码语言:txt
复制
public bool LogOutput { get; set; }
代码语言:txt
复制
public bool LowPriority { get; set; }
代码语言:txt
复制
public bool Maxcpucount { get; set; }
代码语言:txt
复制
public bool MSBuildArchitecture { get; set; }
代码语言:txt
复制
public bool MSBuildExtensionsPath { get; set; }
代码语言:txt
复制
public bool MSBuildExtensionsPath32 { get; set; }
代码语言:txt
复制
public bool MSBuildExtensionsPath64 { get; set; }
代码语言:txt
复制
public bool MSBuildLoadMicrosoftTargetsReadOnly { get; set; }
代码语言:txt
复制
public bool MSBuildNodeMode { get; set; }
代码语言:txt
复制
public bool MSBuildSdksPath { get; set; }
代码语言:txt
复制
public bool MSBuildToolsPath { get; set; }
代码语言:txt
复制
public bool MSBuildToolsVersion { get; set; }
代码语言:txt
复制
public bool MSBuildVersion { get; set; }
代码语言:txt
复制
public bool NoAutoResponse { get; set; }
代码语言:txt
复制
public bool NoConsoleLogger { get; set; }
代码语言:txt
复制
public bool NoLogo { get; set; }
代码语言:txt
复制
public bool NonInteractive { get; set; }
代码语言:txt
复制
public bool OutputResolver { get; set; }
代码语言:txt
复制
public bool Preprocess { get; set; }
代码语言:txt
复制
public bool ProvideProjectDesignation { get; set; }
代码语言:txt
复制
public bool Quiet { get; set; }
代码语言:txt
复制
public bool Rebuild { get; set; }
代码语言:txt
复制
public bool RestorePackages { get; set; }
代码语言:txt
复制
public bool ShowCommandLine { get; set; }
代码语言:txt
复制
public bool ShowConfigFile { get; set; }
代码语言:txt
复制
public bool ShowDescription { get; set; }
代码语言:txt
复制
public bool ShowEventId { get; set; }
代码语言:txt
复制
public bool ShowHelp { get; set; }
代码语言:txt
复制
public bool ShowTargetFrameworkMoniker { get; set; }
代码语言:txt
复制
public bool ShowTimestamp { get; set; }
代码语言:txt
复制
public bool SkipCompilerExecution { get; set; }
代码语言:txt
复制
public bool StopOnFirstFailure { get; set; }
代码语言:txt
复制
public bool TargetFrameworkMoniker { get; set; }
代码语言:txt
复制
public bool TargetFrameworkVersion { get; set; }
代码语言:txt
复制
public bool TargetPath { get; set; }
代码语言:txt
复制
public bool Timeout { get; set; }
代码语言:txt
复制
public bool Toolset { get; set; }
代码语言:txt
复制
public bool Validate { get; set; }
代码语言:txt
复制
public bool Version { get; set; }
代码语言:txt
复制
public bool WarningLevel { get; set; }
代码语言:txt
复制
public bool WarningsAsErrors { get; set; }
代码语言:txt
复制
public bool WarningsNotAsErrors { get; set; }
代码语言:txt
复制
// 重写Execute方法
代码语言:txt
复制
protected override string GenerateCommandLineCommands()
代码语言:txt
复制
{
代码语言:txt
复制
    CommandLineBuilder builder = new CommandLineBuilder();
代码语言:txt
复制
    builder.AppendSwitch("/t:" + Target);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/p:Configuration=", Configuration);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/p:Platform=", Platform);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/nologo", NoLogo);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/noconsolelogger", NoConsoleLogger);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/v:", Verbosity);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/maxcpucount:", MaxCpuCount);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/nodeReuse:", NodeReuse);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/detailedsummary", DetailedSummary);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/ignoreProjectExtensions", IgnoreProjectExtensions);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/validateProjectFile", ValidateProjectFile);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/restore", Restore);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/consoleLoggerParameters", ConsoleLoggerParameters);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/distributedFileLogger", DistributedFileLogger);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/fileLogger", FileLogger);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/fileLoggerParameters", FileLoggerParameters);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/graphBuild", GraphBuild);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/interactive", Interactive);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/isolateProjects", IsolateProjects);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/logCommand", LogCommand);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/logOutput", LogOutput);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/lowPriority", LowPriority);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/maxcpucount", MaxCpuCount);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/MSBuildArchitecture", MSBuildArchitecture);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/MSBuildExtensionsPath", MSBuildExtensionsPath);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/MSBuildExtensionsPath32", MSBuildExtensionsPath32);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/MSBuildExtensionsPath64", MSBuildExtensionsPath64);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/MSBuildLoadMicrosoftTargetsReadOnly", MSBuildLoadMicrosoftTargetsReadOnly);
代码语言:txt
复制
    builder.AppendSwitchIfNotNull("/MSBuildNodeMode
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券