msbuild.exe 有效,但 msbuild API 无效
msbuild.exe works but msbuild API does not
我想使用 MSBuild API 自动构建我的构建,但它给我一个错误。我在 Visual Studio 2015 年有我的自动化项目。它引用了 MSBuild v12.0 dll。
我用来构建解决方案的代码:
private bool Execute()
{
var buildProperties = new Dictionary<string, string>();
buildProperties["Configuration"] = "Debug";
var solution = @"C:\test\test.sln";
bool success = Build(solution, buildProperties)
return success;
}
private bool Build(string solution, Dictionary<string, string> buildProperties)
{
Guard.ValidPath(solution, nameof(solution));
BuildParameters buildParam = new BuildParameters()
BuildRequestData buildRequest = new BuildRequestData(solution, buildProperties, null, new string[] { "Build" }, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(buildParam, buildRequest);
if (buildResult.OverallResult == BuildResultCode.Success)
return true;
return false;
}
解决方案有一个项目。它的配置:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
etc.
我得到的错误:
: ERROR
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Data.Entity.targets(65,5):
The "EntityDeploySplit" task could not be instantiated from the
assembly
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Data.Entity.Build.Tasks.dll".
Please verify the task assembly has been built using the same version
of the Microsoft.Build.Framework assembly as the one installed on your
computer and that your host application is not missing a binding
redirect for Microsoft.Build.Framework. Unable to cast object of type
'Microsoft.Data.Entity.Build.Tasks.EntityDeploySplit' to type
'Microsoft.Build.Framework.ITask'
知道如何克服这个错误吗?为什么会这样?
我设法通过引用 Microsoft.Build.Framework v14.0 解决了这个问题,其他 Microsoft.Build dll 是 v12.0。现在可以使用了!
遇到了类似的问题,但出现了另一条错误消息。我的 Web 项目无法构建,因为他们试图将任务投射到 Microsoft.Build.Framework.ITask。我认为问题在于他们使用的是旧版本,因此无法转换为新版本的 ITask。为 MSBuild 3.5 找到了这个解决方案,它也适用于 14.0。
MSDN Forum: MSBuild crashes with a "Message" task could not be instantiated exception
我将 3.5 更改为 14.0 并将其添加到我的 app.config:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="14.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
我想使用 MSBuild API 自动构建我的构建,但它给我一个错误。我在 Visual Studio 2015 年有我的自动化项目。它引用了 MSBuild v12.0 dll。
我用来构建解决方案的代码:
private bool Execute()
{
var buildProperties = new Dictionary<string, string>();
buildProperties["Configuration"] = "Debug";
var solution = @"C:\test\test.sln";
bool success = Build(solution, buildProperties)
return success;
}
private bool Build(string solution, Dictionary<string, string> buildProperties)
{
Guard.ValidPath(solution, nameof(solution));
BuildParameters buildParam = new BuildParameters()
BuildRequestData buildRequest = new BuildRequestData(solution, buildProperties, null, new string[] { "Build" }, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(buildParam, buildRequest);
if (buildResult.OverallResult == BuildResultCode.Success)
return true;
return false;
}
解决方案有一个项目。它的配置:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
etc.
我得到的错误:
: ERROR C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Data.Entity.targets(65,5): The "EntityDeploySplit" task could not be instantiated from the assembly "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Data.Entity.Build.Tasks.dll". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Data.Entity.Build.Tasks.EntityDeploySplit' to type 'Microsoft.Build.Framework.ITask'
知道如何克服这个错误吗?为什么会这样?
我设法通过引用 Microsoft.Build.Framework v14.0 解决了这个问题,其他 Microsoft.Build dll 是 v12.0。现在可以使用了!
遇到了类似的问题,但出现了另一条错误消息。我的 Web 项目无法构建,因为他们试图将任务投射到 Microsoft.Build.Framework.ITask。我认为问题在于他们使用的是旧版本,因此无法转换为新版本的 ITask。为 MSBuild 3.5 找到了这个解决方案,它也适用于 14.0。
MSDN Forum: MSBuild crashes with a "Message" task could not be instantiated exception
我将 3.5 更改为 14.0 并将其添加到我的 app.config:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="14.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>