VSTS CI - ASP.NET Core 1.1 的构建失败 - Microsoft.Build.Utilities.v4.0 未找到
VSTS CI - Build of ASP.NET Core 1.1 failed - Microsoft.Build.Utilities.v4.0 not found
我为使用 Azure AD B2C 的 ASP.NET Core 1.1 项目设置了 CI(来自本例 - https://github.com/Azure-Samples/active-directory-b2c-dotnetcore-webapp)。所以这是我在 .csproj 文件中的内容:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
...
</ItemGroup>
<ItemGroup>
<PackageReference Include="BuildWebCompiler" Version="1.11.326" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.Identity.Client" Version="1.1.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>
</Project>
当我转到 VSTS 时,我看到以下错误日志:
Starting: Build
******************************************************************************
Task : .NET Core
Description : Build, test and publish using dotnet core command-line.
Version : 1.0.2
Author : Microsoft Corporation
Help : More Information
"C:\Program Files\dotnet\dotnet.exe" build d:\a\s\MMLServices\MMLServices.csproj --configuration release
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build\BuildWebCompiler.targets(15,9): error MSB4062: The "WebCompiler.CompilerBuildTask" task could not be loaded from the assembly C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build..\tools\WebCompiler.exe. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [d:\a\s\MMLServices\MMLServices.csproj]
Build FAILED.
C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build\BuildWebCompiler.targets(15,9): error MSB4062: The "WebCompiler.CompilerBuildTask" task could not be loaded from the assembly C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build..\tools\WebCompiler.exe. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [d:\a\s\MMLServices\MMLServices.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:03.66
Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
Dotnet command failed with non-zero exit code on the following projects : d:\a\s\MMLServices\MMLServices.csproj
那么,我该如何解决这个问题?
更新:
我添加了 debug=true
,这是之后的日志(发布任务):
2017-06-20T15:23:36.6048010Z [command]"C:\Program Files\dotnet\dotnet.exe" publish d:\a\s\MMLServices\MMLServices.csproj --configuration release --output d:\a\a\MMLServices
2017-06-20T15:23:36.7748032Z Microsoft (R) Build Engine version 15.1.1012.6693
2017-06-20T15:23:36.7758030Z Copyright (C) Microsoft Corporation. All rights reserved.
2017-06-20T15:23:36.7758030Z
2017-06-20T15:23:37.3732835Z
C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build\BuildWebCompiler.targets(15,9): error MSB4062: The "WebCompiler.CompilerBuildTask" task could not be loaded from the assembly C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build..\tools\WebCompiler.exe. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [d:\a\s\MMLServices\MMLServices.csproj]
2017-06-20T15:23:37.3943585Z ##[debug]rc:1
2017-06-20T15:23:37.3943585Z ##[debug]success:false
2017-06-20T15:23:37.3973597Z ##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
2017-06-20T15:23:37.3973597Z ##[debug]Processed: ##vso[task.issue type=error;]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
2017-06-20T15:23:37.4003593Z ##[debug]task result: Failed
2017-06-20T15:23:37.4003593Z ##[error]Dotnet command failed with non-zero exit code on the following projects : d:\a\s\MMLServices\MMLServices.csproj
2017-06-20T15:23:37.4003593Z ##[debug]Processed: ##vso[task.issue type=error;]Dotnet command failed with non-zero exit code on the following projects : d:\a\s\MMLServices\MMLServices.csproj
2017-06-20T15:23:37.4034692Z ##[debug]Processed: ##vso[task.complete result=Failed;]Dotnet command failed with non-zero exit code on the following projects : d:\a\s\MMLServices\MMLServices.csproj
2017-06-20T15:23:37.4073330Z ##[section]Finishing: Publish
问题与使用 BuildWebCompiler 包进行构建有关。您可以改用 Visual Studio 构建任务:
- 删除 .NET Core 构建任务
- 添加Visual Studio构建任务(解决方案:***.sln;Visual Studio版本:Visual Studio2017)
更新:
关于发布,可以参考这些步骤(不能使用dotnet publish):
- 在 Visual Studio 中创建网络部署包发布配置文件并添加到源代码管理
样本:
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>Package</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PublishFramework>netcoreapp1.1</PublishFramework>
<ProjectGuid>6ecb453c-aea3-44af-8185-059fbac7b56c</ProjectGuid>
<DesktopBuildPackageLocation>E:\yy\WebApp-OpenIDConnect-DotNet.zip</DesktopBuildPackageLocation>
<PackageAsSingleFile>true</PackageAsSingleFile>
<DeployIisAppPath>Default Web Site/tt</DeployIisAppPath>
<PublishDatabaseSettings>
<Objects xmlns="" />
</PublishDatabaseSettings>
</PropertyGroup>
</Project>
- 删除 .NET Core 任务(例如发布、构建)
- 为 Visual Studio 构建任务指定此 MSBuild 参数
:
/p:DeployOnBuild=true /p:PublishProfile=[publish profile];DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp-OpenIDConnect-DotNet.zip"
好的,我删除了构建定义并添加了一个新定义 - 这次使用 ASP.NET Core (.NET Framework) 模板并且一切正常。
我为使用 Azure AD B2C 的 ASP.NET Core 1.1 项目设置了 CI(来自本例 - https://github.com/Azure-Samples/active-directory-b2c-dotnetcore-webapp)。所以这是我在 .csproj 文件中的内容:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
...
</ItemGroup>
<ItemGroup>
<PackageReference Include="BuildWebCompiler" Version="1.11.326" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.Identity.Client" Version="1.1.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>
</Project>
当我转到 VSTS 时,我看到以下错误日志:
Starting: Build
******************************************************************************
Task : .NET Core Description : Build, test and publish using dotnet core command-line. Version : 1.0.2 Author : Microsoft Corporation
Help : More Information
"C:\Program Files\dotnet\dotnet.exe" build d:\a\s\MMLServices\MMLServices.csproj --configuration release Microsoft (R) Build Engine version 15.1.1012.6693 Copyright (C) Microsoft Corporation. All rights reserved.
C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build\BuildWebCompiler.targets(15,9): error MSB4062: The "WebCompiler.CompilerBuildTask" task could not be loaded from the assembly C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build..\tools\WebCompiler.exe. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [d:\a\s\MMLServices\MMLServices.csproj]
Build FAILED.
C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build\BuildWebCompiler.targets(15,9): error MSB4062: The "WebCompiler.CompilerBuildTask" task could not be loaded from the assembly C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build..\tools\WebCompiler.exe. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [d:\a\s\MMLServices\MMLServices.csproj] 0 Warning(s) 1 Error(s)
Time Elapsed 00:00:03.66 Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1 Dotnet command failed with non-zero exit code on the following projects : d:\a\s\MMLServices\MMLServices.csproj
那么,我该如何解决这个问题?
更新:
我添加了 debug=true
,这是之后的日志(发布任务):
2017-06-20T15:23:36.6048010Z [command]"C:\Program Files\dotnet\dotnet.exe" publish d:\a\s\MMLServices\MMLServices.csproj --configuration release --output d:\a\a\MMLServices 2017-06-20T15:23:36.7748032Z Microsoft (R) Build Engine version 15.1.1012.6693 2017-06-20T15:23:36.7758030Z Copyright (C) Microsoft Corporation. All rights reserved. 2017-06-20T15:23:36.7758030Z 2017-06-20T15:23:37.3732835Z C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build\BuildWebCompiler.targets(15,9): error MSB4062: The "WebCompiler.CompilerBuildTask" task could not be loaded from the assembly C:\Users\buildguest.nuget\packages\buildwebcompiler.11.326\build..\tools\WebCompiler.exe. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [d:\a\s\MMLServices\MMLServices.csproj] 2017-06-20T15:23:37.3943585Z ##[debug]rc:1 2017-06-20T15:23:37.3943585Z ##[debug]success:false 2017-06-20T15:23:37.3973597Z ##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1 2017-06-20T15:23:37.3973597Z ##[debug]Processed: ##vso[task.issue type=error;]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1 2017-06-20T15:23:37.4003593Z ##[debug]task result: Failed 2017-06-20T15:23:37.4003593Z ##[error]Dotnet command failed with non-zero exit code on the following projects : d:\a\s\MMLServices\MMLServices.csproj 2017-06-20T15:23:37.4003593Z ##[debug]Processed: ##vso[task.issue type=error;]Dotnet command failed with non-zero exit code on the following projects : d:\a\s\MMLServices\MMLServices.csproj 2017-06-20T15:23:37.4034692Z ##[debug]Processed: ##vso[task.complete result=Failed;]Dotnet command failed with non-zero exit code on the following projects : d:\a\s\MMLServices\MMLServices.csproj 2017-06-20T15:23:37.4073330Z ##[section]Finishing: Publish
问题与使用 BuildWebCompiler 包进行构建有关。您可以改用 Visual Studio 构建任务:
- 删除 .NET Core 构建任务
- 添加Visual Studio构建任务(解决方案:***.sln;Visual Studio版本:Visual Studio2017)
更新:
关于发布,可以参考这些步骤(不能使用dotnet publish):
- 在 Visual Studio 中创建网络部署包发布配置文件并添加到源代码管理
样本:
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>Package</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PublishFramework>netcoreapp1.1</PublishFramework>
<ProjectGuid>6ecb453c-aea3-44af-8185-059fbac7b56c</ProjectGuid>
<DesktopBuildPackageLocation>E:\yy\WebApp-OpenIDConnect-DotNet.zip</DesktopBuildPackageLocation>
<PackageAsSingleFile>true</PackageAsSingleFile>
<DeployIisAppPath>Default Web Site/tt</DeployIisAppPath>
<PublishDatabaseSettings>
<Objects xmlns="" />
</PublishDatabaseSettings>
</PropertyGroup>
</Project>
- 删除 .NET Core 任务(例如发布、构建)
- 为 Visual Studio 构建任务指定此 MSBuild 参数
:
/p:DeployOnBuild=true /p:PublishProfile=[publish profile];DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp-OpenIDConnect-DotNet.zip"
好的,我删除了构建定义并添加了一个新定义 - 这次使用 ASP.NET Core (.NET Framework) 模板并且一切正常。