Fab*_*Fab 6 c# msbuild .net-core visual-studio-2017
我想构建一个简单的项目或解决方案(VS 2017,.NET Standard/.Net Core):
ProjectCollection pc = new ProjectCollection();
pc.DefaultToolsVersion = "15.0";
ILogger logger = new ConsoleLogger();
pc.Loggers.Add(logger);
Dictionary<string, string> globalProperty = new Dictionary<string, string>();
BuildRequestData buildRequest = new BuildRequestData(fileName, globalProperty, null, new[] { target }, null);
BuildParameters buildParameters = new BuildParameters(pc)
{
DefaultToolsVersion = "15.0",
OnlyLogCriticalEvents = false,
DetailedSummary = true,
Loggers = new List<Microsoft.Build.Framework.ILogger> { logger }.AsEnumerable()
};
var result = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);
return result.OverallResult == BuildResultCode.Success;
Run Code Online (Sandbox Code Playgroud)
但是构建失败并出现以下错误
MSBUILD : warning MSB4196: The "*.overridetasks" files could not be successfully loaded from their expected location "C:\Program Files\dotnet". Default tasks will not be overridden.
MSBUILD : warning MSB4010: The "*.tasks" files could not be successfully loaded from their expected location "C:\Program Files\dotnet". Default tasks will not be available.
D:\Build\workspace\Lx\Lx.sln.metaproj : error MSB4036: The "Message" task was not found.
Check the following:
1.) The name of the task in the project file is the same as the name of the task class.
2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface.
3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files\dotnet" directory.
Run Code Online (Sandbox Code Playgroud)
似乎无法找到正确的目录等......我应该怎么做才能解决这个问题?
注意:我不想从其他目录复制文件。
似乎为了将 BuildManager 与 .Net Core/Visual Studio 2017/MsBuild 15 一起使用,您必须设置几个环境变量:
var msbuildRoot = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild";
var msbuildExe = Path.Combine(msbuildRoot, @"15.0\Bin\MsBuild.exe");
var sdkPath = Path.Combine(msbuildRoot, "Sdks");
Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", msbuildExe);
Environment.SetEnvironmentVariable("MSBUILDSDKSPATH", sdkPath);
Environment.SetEnvironmentVariable("MSBuildExtensionsPath", msbuildRoot);
Run Code Online (Sandbox Code Playgroud)
请注意,前两项应在访问 MsBuild 类之前设置。这是因为它们是由BuildEnvironmentHelper在静态初始化(单例模式)中读取的。检查方法TryFromEnvironmentVariable
以获取更多详细信息。
然而,最后一个MSBuildExtensionsPath
可以通过全局属性来设置,如下所示:
globalProperties.Add("MSBuildExtensionsPath", msbuildRoot);
Run Code Online (Sandbox Code Playgroud)
2020 年 2 月 28 日更新:
已找到Buildalyzer 存储库。似乎无法进行完整的构建,但也许有一些解决方法可以避免扰乱环境。
归档时间: |
|
查看次数: |
1885 次 |
最近记录: |