c# - 升级到 .net 5 程序集缺少框架版本

标签 c# asp.net-mvc asp.net-core .net-5

我正在将项目升级到 .net 5,但在构建时遇到了最奇怪的错误。

 <ResolvePackageAssets 
  ProjectAssetsFile="$(ProjectAssetsFile)"
  ProjectAssetsCacheFile="$(ProjectAssetsCacheFile)"
  ProjectPath="$(MSBuildProjectFullPath)"
  ProjectLanguage="$(Language)"
  EmitAssetsLogMessages="$(EmitAssetsLogMessages)"
  TargetFramework="$(TargetFramework)"
  RuntimeIdentifier="$(RuntimeIdentifier)"
  PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
  RuntimeFrameworks="@(RuntimeFramework)"
  IsSelfContained="$(SelfContained)"
  MarkPackageReferencesAsExternallyResolved="$(MarkPackageReferencesAsExternallyResolved)"
  DisablePackageAssetsCache="$(DisablePackageAssetsCache)"
  DisableFrameworkAssemblies="$(DisableLockFileFrameworks)"
  CopyLocalRuntimeTargetAssets="$(CopyLocalRuntimeTargetAssets)"
  DisableTransitiveProjectReferences="$(DisableTransitiveProjectReferences)"
  DisableTransitiveFrameworkReferences="$(DisableTransitiveFrameworkReferences)"
  DotNetAppHostExecutableNameWithoutExtension="$(_DotNetAppHostExecutableNameWithoutExtension)"
  ShimRuntimeIdentifiers="@(_PackAsToolShimRuntimeIdentifiers)"
  EnsureRuntimePackageDependencies="$(EnsureRuntimePackageDependencies)"
  VerifyMatchingImplicitPackageVersion="$(VerifyMatchingImplicitPackageVersion)"
  ExpectedPlatformPackages="@(ExpectedPlatformPackages)"
  SatelliteResourceLanguages="$(SatelliteResourceLanguages)"
  DesignTimeBuild="$(DesignTimeBuild)"
  ContinueOnError="$(ContinueOnError)"
  PackageReferences="@(PackageReference)">

我正在使用 SimplyCommerce 中的包来创建模块化网站,但收到此错误。

Severity    Code    Description Project File    Line    Suppression State
Error   MSB4044 The "ResolvePackageAssets" task was not given a value for the required parameter "TargetFramework". SimplCommerce.Module.PaymentPaypalExpress   C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets    241 

当我查看程序集详细信息时,我已将其重命名为仓库 crm,但当我查看目标框架时,它显示为空白。尽管我之前已经设置过,但 .net 5 是运行最新 Visual Studio 的工具中的一个错误,当我双击该错误时,它会将我带到此文件

C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets

在您询问之前,.net 5 已安装在目标计算机上。

enter image description here

enter image description here

这是有问题的库的 csproj 文件,您将看到它们不是框架版本,因为它是 razor sdk 库

<Project Sdk="Microsoft.NET.Sdk.Razor">
 
  <PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
 
  <ItemGroup>
    <Content Remove="bundleconfig.json" />
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Include="bundleconfig.json" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Areas\PaymentPaypalExpress\Components\" />
    <Folder Include="Areas\PaymentPaypalExpress\Views\Shared\Components\" />
    <Folder Include="Data\" />
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Warehouse.Infrastructure\Warehouse.Infrastructure\Warehouse.Infrastructure\Warehouse.Infrastructure.csproj" />
  </ItemGroup>

</Project>

最佳答案

.csproj 文件中添加目标框架将解决该问题。

对于.NET 5

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

对于.NET 6

<PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

所有其他版本,另请参阅MSDN - frameworks

关于c# - 升级到 .net 5 程序集缺少框架版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65181472/

相关文章:

c# - 即使在 .NET Core 控制台应用程序中使用 Console.ReadLine(),docker 容器也会立即退出

.net - 有没有办法使用新的 .NET SDK 项目系统禁用 globbing?

c# - ASP.NET Core 表单 POST 导致 HTTP 415 Unsupported Media Type 响应

c# - 正则表达式匹配匹配字符串旁边不包含特定单词的字符串

c# - Xamarin 在错误的位置寻找 android sdks 并给出构建错误

.net - 我应该调用 base.OnAuthorization(filterContext) 吗?

asp.net-mvc - 在 ASP.NET MVC 中的 Controller 内生成 URL

c# - 如何使用 EF 核心在 SQLite 中创建自动增量列?

c# - 将Json String反序列化为多种Object类型

c# - 使用 Windows 域帐户和应用程序管理的帐户