英文:
How to solve error "aspnet_compiler.exe" exited with code 1 when trying to publish web service in Visual Studio 2019?
问题
我在Visual Studio 2019中对Web服务进行了更改,尽管它构建成功,但在尝试发布时出现错误。Web服务基于.NET Framework 4.5.1构建,我看到的错误是:
> C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\Web\Transform\Microsoft.Web.Publishing.AspNetCompileMerge.targets(462,5): Error MSB6006: "aspnet_compiler.exe" exited with code 1.
我尝试过在谷歌上搜索这个错误,但大多数答案都涉及到asp.net页面的问题,而这在这里并不适用,因为项目是一个Web服务。我还尝试重新启动了电脑,但没有任何改变。有人知道如何解决这个问题吗?
更新 03/04/2023
我进行了更多的调查,并在事件查看器中找到了这个:
> 应用程序:csc.exe
Framework版本:v4.0.30319
描述:应用程序通过System.Environment.FailFast(string message)请求进程终止。
消息:System.IO.FileLoadException: 无法加载文件或程序集'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'或其依赖项之一。所定位的程序集清单定义与程序集引用不匹配。(HRESULT 异常:0x80131040)
我不理解这个。代码中没有对System.Runtime.CompilerServices.Unsafe的引用,我们的生产服务器上的代码版本也没有。我尝试使用NuGet添加了这个,但没有任何改变。我还要注意的是,当我尝试运行Web服务时,以及尝试发布时都会出现这个问题。
更新 03/04/2023 - 第2部分
我撤销了所有的更改并重新开始。它仍然无法发布,但现在我得到的错误是:
> 应用程序:csc.exe
Framework版本:v4.0.30319
描述:由于未处理的异常而终止进程。
异常信息:System.IO.FileLoadException
在Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(System.String[])中
这是csc.exe的一个错误吗?如果是,有人知道有什么解决方法吗?
英文:
I have made a change to a web service in Visual Studio 2019 and although it builds it throws an error when I try to publish. The web service is built on .Net Framework 4.5.1, and the error I'm seeing is:
> C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\Web\Transform\Microsoft.Web.Publishing.AspNetCompileMerge.targets(462,5): Error MSB6006: "aspnet_compiler.exe" exited with code 1.
I've tried googling the error but most of the answers talk about issues in asp.net pages, which don't apply here as the project is a web service. I also tried restarting my pc but again it made no difference. Does anyone have any ideas how to fix this, please?
Update 03/04/2023
I did some more investigation and found this in the Event Viewer:
> Application: csc.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I don't understand this. The code has no reference to System.Runtime.CompilerServices.Unsafe, and neither does the version of the code on our live server. I have tried adding this with Nuget but it makes no difference. I should also note that the issue happens when I try to run the web service, as well as when I try to publish it.
Update 03/04/2023 - Part 2
I undid all my changes and started again. It still won't publish, but now the error I get is:
> Application: csc.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileLoadException
at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(System.String[])
Is this a bug with csc.exe? If so, does anyone know a workaround?
答案1
得分: 0
我终于设法使发布工作起来。我找到了我在2022年7月写的一个帖子,里面没有确切的答案,但指引了我正确的方向。基本上我从我的机器上删除了代码,然后从DevOps重新克隆了它。然后我只需修复引用,发布就成功了。
英文:
I finally managed to get the publish to work. I came across a post I wrote in July 2022 which doesn't have an answer as such, but did point me in the right direction. Basically I deleted the code from my machine and re-cloned it from DevOps. Then I just had to fix the references and the publish worked.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论