我正在尝试深入研究 ASP.NET Core。所以,我决定尝试使用 VS Code 创建一个宠物项目。
在 dotnet cmd 的帮助下,我创建了一个解决方案,将项目添加到其中(应用程序、测试、EF、映射等)并在项目之间设置引用。
但是现在当我尝试运行解决方案时,我得到了 Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute
错误和一堆其他奇怪的错误。这是我遇到的一些错误:
c:\Projects\dotNet\BestTongue\Utilities\objBinRemove\obj\Debug\netcoreapp3.0\objBinRemove.AssemblyInfo.cs(10,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [C:\Projects\dotNet\BestTongue\BestTongue.csproj]
c:\Projects\dotNet\BestTongue\Utilities\objBinRemove\obj\Debug\netcoreapp3.0\objBinRemove.AssemblyInfo.cs(11,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [C:\Projects\dotNet\BestTongue\BestTongue.csproj]
...
我不确定我还需要在我的问题中添加什么才能使问题可以解决。所以,如果我错过了什么,请在评论中询问所有必要的细节。
我花了很多时间试图找到问题的解决方案,但徒劳无功。
更新
正如评论部分所推荐的那样,我尝试使用 the related question 中提到的解决方案.
我试图添加:
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
所以,现在我的
.csproj
看起来像这样:<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\App\App.csproj" />
<ProjectReference Include="..\Data\Data.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>netstandard3.0</TargetFramework>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
</PropertyGroup>
</Project>
但我仍然看到相同的错误:
此外,我编写了一个脚本,该脚本遍历所有项目并删除
*.AssemblyInfo.cs
.之后我检查了建筑项目是否会带来*.AssemblyInfo.cs
背部。和 *.AssemblyInfo.cs
确实在构建后再次出现。另外,现在(在 .csproj
文件修改之后)我收到了一个新错误:C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(140,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Standard 3.0. Either target .NET Standard 2.1 or lower, or use a version of the .NET SDK that supports .NET Standard 3.0. [C:\Projects\dotNet\BestTongue\Controllers\Controllers.csproj] C:\Program
Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(140,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Standard 3.0. Either target .NET Standard 2.1 or lower, or use a version of the .NET SDK that supports .NET Standard 3.0. [C:\Projects\dotNet\BestTongue\App\App.csproj]
对于试图帮助我在本地检查解决方案的人来说,这可能很有用。 Here是具有最新更改的解决方案存储库。
最佳答案
这是(上面的 Ian Kemp 第 1 项。)我正在将 .net 应用程序升级到 .net core 5,为摆脱这个问题付出了艰辛的努力。现在一切都很好。
对您的 .net 核心应用程序进行文件搜索(我假设 3.X 是相同的)并删除所有 AssemblyInfo.cs 文件(.net 核心从项目文件中构建 AssembleyInfo,因此如果您也删除这些文件也无所谓。
重新编译,问题就会消失。
另外,请确保您的库 (DLL) 文件在属性组中都是“库”...例如
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net5.0</TargetFramework>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
关于asp.net-core - 重复 'System.Reflection.AssemblyInformationalVersionAttribute' 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59571556/