【问题标题】:error MSB4018: The "CopyRefAssembly" task failed unexpectedly错误 MSB4018:“CopyRefAssembly”任务意外失败
【发布时间】:2021-01-22 21:42:40
【问题描述】:

这个错误似乎只是随机发生的。我已经进行了互联网搜索,但没有任何结果。如果我清理 bin、obj 和 .vs 目录,它会在几次构建中修复它,然后错误会再次出现。

1>------ Build started: Project: GridViewOnly, Configuration: Debug Any CPU ------
1>Failed to check the content hash of the destination ref assembly 'C:\Users\myuser\source\repos\GridViewOnly\bin\Debug\net5.0-windows\ref\GridViewOnly.dll'. It will be overwritten.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4413,5): error MSB4018: The "CopyRefAssembly" task failed unexpectedly.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4413,5): error MSB4018: System.InvalidOperationException: The "CopyRefAssembly" task has not registered its resources. In order to use the "TaskLoggingHelper.FormatResourceString()" method this task needs to register its resources either during construction, or via the "TaskResources" property.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4413,5): error MSB4018:    at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4413,5): error MSB4018:    at Microsoft.Build.Shared.ErrorUtilities.VerifyThrowInvalidOperation(Boolean condition, String resourceName, Object arg0)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4413,5): error MSB4018:    at Microsoft.Build.Utilities.TaskLoggingHelper.FormatResourceString(String resourceName, Object[] args)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4413,5): error MSB4018:    at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorWithCodeFromResources(String messageResourceName, Object[] messageArgs)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4413,5): error MSB4018:    at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Copy()
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4413,5): error MSB4018:    at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Execute()
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4413,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4413,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
1>Done building project "GridViewOnly.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

【问题讨论】:

    标签: msbuild visual-studio-2019


    【解决方案1】:

    我使用配置管理器创建了一个 x64 配置,这似乎可以解决它。无论如何,自从我几天前这样做以来,我还没有遇到过这个问题。之前,我只是使用默认的 AnyCPU 配置。我最终删除了它,因为我知道我不需要它。

    【讨论】:

      【解决方案2】:

      在解决方案的 csproj 文件中将 ProduceReferenceAssembly 添加为 false

      <PropertyGroup>
       <TargetFramework>net5.0</TargetFramework> 
       <ProduceReferenceAssembly>false</ProduceReferenceAssembly> 
      </PropertyGroup>
      

      【讨论】:

      • 您可以添加一个示例,例如&lt;PropertyGroup&gt; &lt;TargetFramework&gt;net5.0&lt;/TargetFramework&gt; &lt;ProduceReferenceAssembly&gt;false&lt;/ProduceReferenceAssembly&gt; &lt;/PropertyGroup&gt;
      • 对于 .NET 5.0+,Rahul 就是答案。 Matt 可能也可以,但我认为问题出在 .NET 5 创建的 refs 文件夹上。
      猜你喜欢
      • 2011-10-06
      • 2016-02-23
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 2021-03-22
      • 2020-07-18
      • 2021-02-25
      • 1970-01-01
      相关资源
      最近更新 更多