首页
学习
活动
专区
工具
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
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

2分23秒

如何从通县进入虚拟世界

496
7分21秒

python开发视频课程2.5-如何调用模板

21分43秒

Python从零到一:Python函数的定义与调用

8分0秒

【技术创作101训练营】从函数调用到栈溢出攻击

1.3K
-

双11是如何从“光棍节”走到“剁手节”的?

-

从交换机到5G,华为如何实现反超?

1时33分

从校园到行业:如何成为炙手可热的音视频技术人才?

2分27秒

DOE是如何从关键因素中找到最佳参数组合的?

1分41秒

从线下到线上,中小型银行如何做好网贷风控

14.6K
1分45秒

从线下到线上,中小型银行如何做好网贷风控?

1时35分

从流量到新基建,教育企业如何破解数字化升级难题?

7分37秒

面试题:从库延迟,如何快速解决 循环分批次批量更改数据

领券