"" TransformWebConfig"任务意外失败"在dotnet上发布

时间:2018-01-08 01:04:10

标签: .net publish

我在发布ASP.NET Core 2.0 Web应用程序时遇到问题。

实际上这个项目是我构建的开源模板。您可以查看:https://github.com/diegoortizmatajira/aspnetboilerplate_template

应用程序构建并运行正常,但是当我执行dotnet publish命令时,它显示了一个meesage:

  

" TransformWebConfig"任务意外失败。

该应用程序不需要web.config文件(在IIS中使用),因为它应该在linux docker容器内运行。

执行结果显示如下:

user@laptop:~/codeworkshop/Templates/WebApiTemplate$ dotnet publish
Microsoft (R) Build Engine version 15.5.179.9764 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 45.95 ms for /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.Core/WebApiTemplate.Core.csproj.
  Restore completed in 42.53 ms for /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.Application/WebApiTemplate.Application.csproj.
  Restore completed in 44.98 ms for /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.EntityFrameworkCore/WebApiTemplate.EntityFrameworkCore.csproj.
  Restore completed in 5.89 ms for /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj.
  Restore completed in 38.66 ms for /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.EntityFrameworkCore/WebApiTemplate.EntityFrameworkCore.csproj.
  Restore completed in 26.94 ms for /home/user/codeworkshop/Templates/WebApiTemplate/test/WebApiTemplate.Test/WebApiTemplate.Test.csproj.
  Restore completed in 48.07 ms for /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj.
  Restore completed in 50.32 ms for /home/user/codeworkshop/Templates/WebApiTemplate/test/WebApiTemplate.WebApi.Test/WebApiTemplate.WebApi.Test.csproj.
  Restore completed in 16.46 ms for /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj.
  WebApiTemplate.Core -> /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.Core/bin/Debug/netstandard2.0/WebApiTemplate.Core.dll
  WebApiTemplate.Core -> /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.Core/bin/Debug/netstandard2.0/publish/
  WebApiTemplate.Application -> /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.Application/bin/Debug/netstandard2.0/WebApiTemplate.Application.dll
  WebApiTemplate.EntityFrameworkCore -> /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.EntityFrameworkCore/bin/Debug/netstandard2.0/WebApiTemplate.EntityFrameworkCore.dll
  WebApiTemplate.EntityFrameworkCore -> /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.EntityFrameworkCore/bin/Debug/netstandard2.0/publish/
  WebApiTemplate.Application -> /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.Application/bin/Debug/netstandard2.0/publish/
  WebApiTemplate.Test -> /home/user/codeworkshop/Templates/WebApiTemplate/test/WebApiTemplate.Test/bin/Debug/netcoreapp2.0/WebApiTemplate.Test.dll
  WebApiTemplate.WebApi -> /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/bin/Debug/netcoreapp2.0/WebApiTemplate.WebApi.dll
  WebApiTemplate.WebApi -> /home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/bin/Debug/netcoreapp2.0/publish/
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018: The "TransformWebConfig" task failed unexpectedly. [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018: System.ArgumentOutOfRangeException: Length cannot be less than zero. [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018: Parameter name: length [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at System.String.Substring(Int32 startIndex, Int32 length) [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at System.Uri.CreateHostStringHelper(String str, UInt16 idx, UInt16 end, Flags& flags, String& scopeId) [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at System.Uri.CreateHostString() [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at System.Uri.EnsureHostString(Boolean allowDnsOptimization) [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at System.Uri.GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat) [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at System.Uri.ToString() [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at System.Xml.XmlTextReaderImpl..ctor(String uriStr, XmlReaderSettings settings, XmlParserContext context, XmlResolver uriResolver) [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext) [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings) [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options) [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute() [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() in E:\A\_work\45\s\src\Build\BackEnd\TaskExecutionHost\TaskExecutionHost.cs:line 631 [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
/usr/share/dotnet/sdk/2.1.3/Sdks/Microsoft.NET.Sdk.Publish/build/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets(46,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__25.MoveNext() in E:\A\_work\45\s\src\Build\BackEnd\Components\RequestBuilder\TaskBuilder.cs:line 787 [/home/user/codeworkshop/Templates/WebApiTemplate/src/WebApiTemplate.WebApi/WebApiTemplate.WebApi.csproj]
  WebApiTemplate.Test -> /home/user/codeworkshop/Templates/WebApiTemplate/test/WebApiTemplate.Test/bin/Debug/netcoreapp2.0/publish/
  WebApiTemplate.WebApi.Test -> /home/user/codeworkshop/Templates/WebApiTemplate/test/WebApiTemplate.WebApi.Test/bin/Debug/netcoreapp2.0/WebApiTemplate.WebApi.Test.dll
  WebApiTemplate.WebApi.Test -> /home/user/codeworkshop/Templates/WebApiTemplate/test/WebApiTemplate.WebApi.Test/bin/Debug/netcoreapp2.0/publish/

我的开发设置是:

Herramientas de la línea de comandos .NET (2.1.3)

Product Information:
 Version:            2.1.3
 Commit SHA-1 hash:  a0ca411ca5

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  17.10
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/2.1.3/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.4
  Build    : 7f262f453d8c8479b9af91d34c013b3aa05bc1ff

但是在容器内发布时也失败了。

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我在下面的问题中通过“Andy Raddatz”的回答解决了这个问题: The "TransformWebConfig" task failed unexpectedly - System.Exception: The acceptable value for AspNetCoreModuleHostingModel property is either

只需将此代码添加到您的应用程序“.csproj”:

<PropertyGroup>
  <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>

答案 1 :(得分:0)

这是一个错误:(尝试更新您的Visual Studio。如果不能解决问题,则可以在网络项目中编辑.csproj文件并删除以下行:

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

什么是进程内托管模型?

https://dotnettutorials.net/lesson/asp-net-core-inprocess-hosting/