.NET Core 3.1 – 无法加载文件或程序集 System.Runtime,版本=4.2.2.0

huangapple go评论151阅读模式
英文:

.NET Core 3.1 - Could not load file or assembly System.Runtime, Version=4.2.2.0

问题

.NET Core 3.1控制台应用在构建过程中生成错误 -

> System.IO.FileNotFoundException: 无法加载文件或程序集
> 'System.Runtime, Version=4.2.2.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a'。系统找不到指定的文件。

但在.NET Core 3.0版本上可以正常工作。

我正在使用Microsoft.Orleans。这是csproj文件 -

    <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Orleans.Core" Version="3.0.2" />
    <PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator.Build" Version="3.0.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>
英文:

.NET Core 3.1 console app generates error during build -

> System.IO.FileNotFoundException: Could not load file or assembly
> 'System.Runtime, Version=4.2.2.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file
> specified.

But it works on .NET Core 3.0 version.

I'm using Microsoft.Orleans. This is csproj -

    <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Orleans.Core" Version="3.0.2" />
    <PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator.Build" Version="3.0.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

答案1

得分: 9

在我的情况下,Nischal Nigam的解决方案没有起作用,所以我所做的是,我将Microsoft.NET.Sdk.Functions包从版本1.0...更新到3.0.11,之后它就正常工作了。

英文:

In my case Nischal Nigam's solution didn't worked out, so what I did, I updated the package Microsoft.NET.Sdk.Functions from version 1.0... to 3.0.11 and after that it started working just fine.

答案2

得分: 9

确保正确加载您的项目(不仅仅是包含项目的文件夹)。在我的情况下,我加载的不是.csproj文件,而是加载了包含整个项目的文件夹。然后,我重新加载并明确点击了.csproj文件,然后它恢复正常。

英文:

Make sure you load your project properly (not just the folder which contains the project). In my case, instead of loading the .csproj file, I loaded just the folder which contains the whole project. What I did then, reloaded and clicked the .csproj file explicitly, then it came back to normal.

答案3

得分: 8

我正在使用Microsoft Visual Studio - 版本16.4.5

前往以下位置并在文本编辑器中打开devenv.exe.config文件:

C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\16.0_1832c881\devenv.exe.config

将此绑定粘贴到<configuration> -> <runtime> -> <assemblyBinding>

<dependentAssembly>
  <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
  <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>

完成后,保存文件并重新启动Visual Studio。

英文:

I am using Microsoft Visual Studio - Version 16.4.5

Go to the following location and open the devenv.exe.config file in a text editor:

C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\16.0_1832c881\devenv.exe.config

Paste this binding in <configuration> -> <runtime> -> <assemblyBinding>

> <dependentAssembly>
> <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.0.0.0"/>
> </dependentAssembly>

After this, save the file and restart Visual Studio.

答案4

得分: 2

ReubenBond帮助我解决了问题。我使用了Microsoft.Orleans.CodeGenerator.MSBuild包,而不是Microsoft.Orleans.OrleansCodeGenerator.Build

英文:

ReubenBond helped me with solution. I used Microsoft.Orleans.CodeGenerator.MSBuild package instead of Microsoft.Orleans.OrleansCodeGenerator.Build.

答案5

得分: 0

  1. 双击“NameOfYourFile.csproj”文件以加载您的项目。
  2. 在菜单栏中,单击“项目” => “NameOfYourFile的属性”。选择“应用程序”并选择一个有效的框架目标(列表中的最新版本)。
  3. 重新构建,应该可以正常工作。
英文:
  1. Load your project by double clicking on the "NameOfYourFile.csproj"
  2. In the menu bar, click Project => properties of "NameOfYourFile. Choose "Application" and select a valid Framework Target (the newest in the list).
  3. Rebuil, it should work.

huangapple
  • 本文由 发表于 2020年1月6日 17:59:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/59610009.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定