我是 JetBrains 产品的用户,更具体地说是 IDE Rider。
我的同事主要是微软产品的用户,更具体地说是Visual Studio。
因此,当他在 Visual Studio 中打开我的解决方案或 c# 项目时,我感到相当惊讶,它们被破坏了。(具体项目的属性)
![ms-visual-studio-error](https://i.stack.imgur.com/VDtTI.png)
该错误有点误导,因为提到的常量实际上是定义的。
这也具有误导性,因为错误的原因是在.csproj
-file.
对我来说,这个错误与原因有些无关,因此我对如何继续感到非常困惑。
这是该错误的完整输出:
System.ArgumentException: Expected 1 values for property Build::DefineConstants, but got 0.
Parameter name: values
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.Property.Update(ImmutableArray`1 values)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.Property..ctor(PropertyMetadata metadata, ImmutableArray`1 values, PropertyContext context, ImmutableHashSet`1 varyByDimensions)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.PropertyContextFactoryBase.ToProperty(IUIProperty property, Page page, Category category, Int32 order, PropertyContext propertyContext, IPropertyEditorRegistry propertyEditorRegistry)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertyDataAccess.Observer.<HandleDataAsync>g__CreateProperties|14_5(<>c__DisplayClass14_0& )
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertyDataAccess.Observer.<HandleDataAsync>g__ProcessInitialData|14_1(<>c__DisplayClass14_0& )
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertyDataAccess.Observer.<InitializeAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertyDataAccess.Observer.<CreateAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.ProjectPropertiesEditor.<>c__DisplayClass0_0.<<-ctor>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.Designer.AsyncLoadContent.<>c__DisplayClass0_0.<<Initialize>b__0>d.MoveNext()
但我可以在 Rider 中毫无问题地打开这些项目属性:
![jetbrains-rider-project-properties](https://i.stack.imgur.com/vasxH.png)
我已将问题范围缩小到特定的信息属性,我用它来将信息放入 NuGet 包中。本文档/指南提到我应该为此使用程序集信息,但我在使用时遇到了获取程序集信息的问题nuget pack
,这就是为什么我在.csproj
-file.
然后我求助于以下信息“使用 MSBuild 创建 NuGet 包”-文档,这是更好的选择,因为我可以将打包集成到构建中。
通过添加 NuGet-Target-Package,我看到 Rider 中出现了一个新选项卡,它允许我编辑这些信息。
这让我感觉我在 Rider 中做了正确的事情,但在 Visual Studio 中看到结果,让我看起来像是在对我不知道的 NuGet 规范做了非常无意的事情。
编辑!这是 csproj 文件的完整版本
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{63B8CCEF-5C50-4F25-8E6B-C623DA1BDD2F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Testcenter.RobotFramework</RootNamespace>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<AssemblyName>Testcenter.RobotFramework</AssemblyName>
<FileAlignment>512</FileAlignment>
<DefineConstants>DEBUG</DefineConstants>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<!-- Properties which cause problems in Visual Studio. The error doesn't occur if these are commented out.
<TargetFramework>netframework4.8</TargetFramework>
<PackageId>Testcenter.RobotFramework</PackageId>
<Version>1.0.0</Version>
<Authors>Testcenter Team, Some Person</Authors>
<Company>SomeCompany</Company>
<PackageOutputPath>$(ProjectDir)</PackageOutputPath>
<Description>A class library to implement a remote library interface conforming to RobotFramework.</Description>
<Title>RobotFramework Remote-Library-Interface for C#</Title>
<Copyright>Copyright (c) SomeCompany 2022</Copyright>
<RepositoryUrl>https://redacted.url.com</RepositoryUrl>
<Product>Testcenter.RobotFramework</Product>
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion> -->
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Testing|AnyCPU' ">
<OutputPath>bin\Testing\</OutputPath>
<DefineConstants>TEST</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Libraries|AnyCPU' ">
<OutputPath>bin\Libraries\</OutputPath>
<DefineConstants>ONLY_LIBRARY</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration\LibraryConfig.cs" />
<Compile Include="Configuration\ServerConfiguration.cs" />
<Compile Include="Configuration\XML\AssemblyElement.cs" />
<Compile Include="Configuration\XML\AssemblyElementCollection.cs" />
<Compile Include="Configuration\XML\PortElement.cs" />
<Compile Include="Configuration\XML\XmlServerConfiguration.cs" />
<Compile Include="Keyword\IKeywordManager.cs" />
<Compile Include="Keyword\Keyword.cs" />
<Compile Include="Keyword\KeywordErrorType.cs" />
<Compile Include="Keyword\KeywordManager.cs" />
<Compile Include="Keyword\KeywordResult.cs" />
<Compile Include="Keyword\KeywordStatus.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Trash\XmlDocumentation.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="README.md" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="5.1.0" />
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="6.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Testcenter.RobotFramework.Exceptions" Version="1.0.0" />
<PackageReference Include="Testcenter.TestAutomation.Utility" Version="1.0.0" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
我的目的是将NuGet包信息嵌入到相应的项目文件中,而不需要创建一个.nuspec
.
但遇到这个错误后,感觉这可能是一场误会。
我现在非常不确定什么是正确的,在以下方面:
- 如果我要遵守某些“规范”,我应该将这些 NuGet-Assembly 信息放在哪里?(我没有找到必要的信息)
- 从 .Net 框架包创建 NuGet 包时,我通常需要 NuGet-Spec 文件吗?(NuGet-Spec 到底是什么?为什么我需要它?)
- 和有什么区别.Net NuGet 包 and a .Net框架包?
我发现所有这些都非常令人困惑,因为在打包 C# 项目或创建 NuGet 方面我还很陌生。
但我被迫使用 .NET Framework 4.8,与 .NET core 相比,这显然使得这个过程不是很简单。