如何使用“ BuildManager”从C#代码构建.Net Core应用程序?

时间:2019-06-06 10:44:44

标签: c# .net-core msbuild

我想从C#代码构建.Net Core 2.1控制台应用程序。我正在使用BuildManager来构建解决方案。

$('#line').on('click', function() {
    chart.series[0].update({
        type: 'line',
        dataGrouping: {
            approximation: 'average'
        },
        keys: ['x', 'y'],
        data: line
    });
});

$('#candlestick').on('click', function() {
    chart.series[0].update({
        type: 'candlestick',
        dataGrouping: {
            approximation: 'ohlc'
        },
        keys: ['x', 'open', 'high', 'low', 'close'],
        data: candlestick
    });
});

我已经设置了这样的环境变量:

               using (var buildManager = new BuildManager())
                {
                    var bp = new BuildParameters(projectCollection)
                    {
                        Loggers = new List<ILogger>
                        {
                            logger
                        },
                        OnlyLogCriticalEvents = false,
                        DetailedSummary = true,
                        NodeExeLocation = @"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\MSBuild\\Current\\Bin\\MSBuild.exe"
                    };

                    var buildRequest = new BuildRequestData(
                        "projectFullPath",
                        globalProperties, null, new[] { "Build" }, null,
                        BuildRequestDataFlags.ReplaceExistingProjectInstance);

                    BuildSubmission submission = null;

                    buildManager.BeginBuild(bp);
                    submission = buildManager.PendBuildRequest(buildRequest);

                    buildResult = submission.Execute();
                    buildManager.EndBuild();

globalProperties:

        Environment.SetEnvironmentVariable("MSBuildExtensionsPath", globalProperties["MSBuildExtensionsPath"]);
        Environment.SetEnvironmentVariable("MSBuildFrameworkToolsPath", globalProperties["MSBuildFrameworkToolsPath"]);
        Environment.SetEnvironmentVariable("MSBuildToolsPath32", globalProperties["MSBuildToolsPath32"]);
        Environment.SetEnvironmentVariable("MSBuildSDKsPath", globalProperties["MSBuildSDKsPath"]);
        Environment.SetEnvironmentVariable("RoslynTargetsPath", globalProperties["RoslynTargetsPath"]);

现在我有构建错误。

            Path.Combine(programFilesX86, @"Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\msbuild.exe"),
            Path.Combine(programFilesX86,
                @"Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"),
            Path.Combine(programFilesX86, @"Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"),
            Path.Combine(programFilesX86, @"Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe"),
            Path.Combine(programFilesX86, @"MSBuild\14.0\Bin\MSBuild.exe"),
            Path.Combine(programFilesX86, @"MSBuild\12.0\Bin\MSBuild.exe")

1 个答案:

答案 0 :(得分:0)

我能够通过安装“Microsoft.Build.Runtime”nuget 包来解决这个问题,该包解决了丢失的 *.overridestasks 和 *.tasks 错误