VSTS CI - ASP.NET 核心 1.1 的生成失败 - 找不到 Microsoft.Build.Utiliti



我为使用 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 时,我看到以下日志错误:


开始:构建

**

**

任务 : .NET Core 说明 : 使用 dotnet 核心命令行生成、测试和发布。 版本 : 1.0.2 作者 : Microsoft公司

帮助 : 更多信息

"C:\Program Files\dotnet\dotnet.exe" build d:\a\1\s\MMLServices\MMLServices.csproj --configuration release Microsoft (R) 生成引擎版本 15.1.1012.6693 版权所有 (C) Microsoft 公司。保留所有权利。

C:\Users\buildguest.nuget\packages\buildwebcompiler\1.11.326\build\BuildWebCompiler.targets(15,9):错误MSB4062:"WebCompiler.CompilerBuildTask"任务无法从程序集 C:\Users\buildguest.nuget\packages\buildwebcompiler\1.11.326\build..\tools\WebCompiler.exe.无法加载文件或程序集"Microsoft.Build.Utilities.v4.0,版本=4.0.0.0,区域性=中性,公钥令牌=b03f5f7f11d50a3a"。系统找不到指定的文件。确认声明正确,程序集及其所有依赖项可用,并且任务包含实现 Microsoft.Build.Framework.ITask 的公共类。[d:\a\1\s\MMLServices\MMLServices.csproj]

生成失败。

C:\Users\buildguest.nuget\packages\buildwebcompiler\1.11.326\build\BuildWebCompiler.targets(15,9):错误MSB4062:"WebCompiler.CompilerBuildTask"任务无法从程序集 C:\Users\buildguest.nuget\packages\buildwebcompiler\1.11.326\build..\tools\WebCompiler.exe.无法加载文件或程序集"Microsoft.Build.Utilities.v4.0,版本=4.0.0.0,区域性=中性,公钥令牌=b03f5f7f11d50a3a"。系统找不到指定的文件。确认声明正确,程序集及其所有依赖项可用,并且任务包含实现 Microsoft.Build.Framework.ITask 的公共类。[d:\a\1\s\MMLServices\MMLServices.csproj] 0 警告 1 错误

已用时间 00:00:03.66 错误:C:\程序文件\dotnet\dotnet.exe失败,返回代码:1 Dotnet 命令失败,在以下项目上出现非零退出代码:d:\a\1\s\MMLServices\MMLServices.csproj

那么,我该如何解决这个问题呢?

更新:

我添加了debug=true,这是之后的日志(发布任务):

2017-06-20T15:23:36.6048010Z [命令]"C:\Program Files\dotnet\dotnet.exe" publish d:\a\1\s\MMLServices\MMLServices.csproj --configuration release --output d:\a\1\a\MMLServices 2017-06-20T15:23:36.7748032Z Microsoft (R) 构建引擎版本 15.1.1012.6693 2017-06-20T15:23:36.7758030Z 版权所有(C)Microsoft公司。保留所有权利。 2017-06-20T15:23:36.7758030Z 2017-06-20T15:23:37.3732835Z C:\Users\buildguest.nuget\packages\buildwebcompiler\1.11.326\build\BuildWebCompiler.targets(15,9):错误MSB4062:"WebCompiler.CompilerBuildTask"任务无法从程序集 C:\Users\buildguest.nuget\packages\buildwebcompiler\1.11.326\build..\tools\WebCompiler.exe.无法加载文件或程序集"Microsoft.Build.Utilities.v4.0,版本=4.0.0.0,区域性=中性,公钥令牌=b03f5f7f11d50a3a"。系统找不到指定的文件。确认声明正确,程序集及其所有依赖项可用,并且任务包含实现 Microsoft.Build.Framework.ITask 的公共类。[d:\a\1\s\MMLServices\MMLServices.csproj] 2017-06-20T15:23:37.3943585Z ##[debug]rc:1 2017-06-20T15:23:37.3943585Z ##[调试]成功:假 2017-06-20T15:23:37.3973597Z ##[错误]错误:C:\程序文件\dotnet\dotnet.exe失败,返回代码:1 2017-06-20T15:23:37.3973597Z ##[调试]已处理:##vso[任务.问题类型=错误;]错误:C:\程序文件\dotnet\dotnet.exe失败,返回代码:1 2017-06-20T15:23:37.4003593Z ##[调试]任务结果:失败 2017-06-20T15:23:37.4003593Z ##[error]Dotnet 命令失败,以下项目上的退出代码为非零:d:\a\1\s\MMLServices\MMLServices.csproj 2017-06-20T15:23:37.4003593Z ##[调试]已处理:##vso[任务.问题类型=错误;]Dotnet 命令失败,在以下项目上出现非零退出代码:d:\a\1\s\MMLServices\MMLServices.csproj 2017-06-20T15:23:37.4034692Z ##[调试]已处理:##vso[任务.完整结果=失败;]Dotnet 命令失败,在以下项目上出现非零退出代码:d:\a\1\s\MMLServices\MMLServices.csproj 2017-06-20T15:23:37.4073330Z ##[部分]整理:发布

这个问题与使用BuildWebCompiler包构建有关。您可以改用Visual Studio Build任务:

  1. 删除 .NET 核心生成任务
  2. 添加视觉工作室生成任务(解决方案:****.sln;Visual Studio 版本:Visual Studio 2017)

更新:

关于发布,可以参考以下步骤(不能使用 dotnet 发布):

  1. 在 Visual Studio 中创建 Web 部署包发布配置文件并添加到源代码管理

样本:

<?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:yyWebApp-OpenIDConnect-DotNet.zip</DesktopBuildPackageLocation>
<PackageAsSingleFile>true</PackageAsSingleFile>
<DeployIisAppPath>Default Web Site/tt</DeployIisAppPath>
<PublishDatabaseSettings>
<Objects xmlns="" />
</PublishDatabaseSettings>
</PropertyGroup>
</Project>
  1. 删除 .NET Core 任务(例如发布、生成)
  2. 指定此 MSBuild 参数 Visual Studio 生成任务

/p:DeployOnBuild=true /p:PublishProfile=[publish profile];DesktopBuildPackageLocation="$(build.artifactstagingdirectory)WebApp-OpenIDConnect-DotNet.zip"

好的,我删除了该构建定义并添加了一个新的定义 - 这次使用 ASP.NET 核心(.NET Framework)模板,一切正常。

最新更新