.net 由于缺少DefineConstants值而导致项目加载错误,但这些值已定义

yc0p9oo0  于 2023-03-04  发布在  .NET
关注(0)|答案(1)|浏览(178)

我有一个.Net-framework 4.8项目无法在Visual Studio 2022中加载,我只是不知道为什么。
尝试在Visual Studio中打开项目的属性时发生错误。

这些项目还在解决方案资源管理器中显示了一个错误,但没有进一步说明:

我在另一个项目中也遇到过同样的问题,但通过移除非法财产解决了。
在我当前的项目中,该属性已被移除,但错误仍然存在且无法解决。我不明白幕后发生了什么。

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()

下面是项目文件:

<?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>{DA53C3E0-7D05-4BB7-932C-97147BFB0E4C}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Testcenter.RobotFramework.Exceptions</RootNamespace>
    <AssemblyName>Testcenter.RobotFramework.Exceptions</AssemblyName>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <DefineConstants>DEBUG</DefineConstants>
  </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>
  <PropertyGroup>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <PackageId>Testcenter.RobotFramework.Exceptions</PackageId>
    <Version>1.0.0</Version>
    <Authors>Testcenter Team, Some person</Authors>
    <Company>Some company</Company>
    <PackageOutputPath>$(ProjectDir)</PackageOutputPath>
    <Description>A class library providing exception types used in the implementation itself and in keyword libraries.</Description>
    <Title>RobotFramework Remote-Library-Interface for C# (exception types)</Title>
    <Copyright>Copyright (c) Some company 2022</Copyright>
    <RepositoryUrl>https://redacted-url.com/repos/testcenter.robotframework/browse</RepositoryUrl>
    <Product>Testcenter.RobotFramework.Exceptions</Product>
    <AssemblyVersion>1.0.0</AssemblyVersion>
    <FileVersion>1.0.0</FileVersion>
    <!-- Properties which cause problems in Visual Studio. The error doesn't occur if these are commented out.
    More info here: https://stackoverflow.com/questions/75098414/unrelated-loading-error-when-adding-nuget-package-information-to-a-net-framewor
    <TargetFramework>net48</TargetFramework> -->
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Configuration\ConfigurationException.cs" />
    <Compile Include="Configuration\KeywordConfigurationException.cs" />
    <Compile Include="Configuration\ServerConfigurationException.cs" />
    <Compile Include="Keyword\ContinuableKeywordException.cs" />
    <Compile Include="Keyword\FatalKeywordException.cs" />
    <Compile Include="Keyword\KeywordException.cs" />
    <Compile Include="Keyword\NormalKeywordException.cs" />
    <Compile Include="Keyword\KeywordLoadingException.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="NuGet.Build.Tasks.Pack" Version="6.4.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </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>

该项目仅在Visual Studio中加载失败,但在JetBrains Rider中加载正常。
我有一个非常相似的项目文件 (在解决方案资源管理器中看到),它加载得很好,具有完全相同的属性结构,唯一的区别是NuGet-Package信息和编译的源文件。
这也是我的解决方案文件,它可能导致了这个问题,但我不知道为什么或如何。

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32901.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcenter.RobotFramework", "Testcenter.RobotFramework\Testcenter.RobotFramework.csproj", "{63B8CCEF-5C50-4F25-8E6B-C623DA1BDD2F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testcenter.RobotFramework.Communication", "Testcenter.RobotFramework.Communication\Testcenter.RobotFramework.Communication.csproj", "{86F3BACB-FC4D-43FC-BA20-659600C6134C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testcenter.RobotFramework.Exceptions", "Testcenter.RobotFramework.Exceptions\Testcenter.RobotFramework.Exceptions.csproj", "{DA53C3E0-7D05-4BB7-932C-97147BFB0E4C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RobotFramework", "RobotFramework", "{1F0EA3DB-C080-432A-9948-DF8461982CDE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Testing", "Testing", "{0A74D269-D322-40B9-9193-AC95B08DA488}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcenter.RobotFramework.Test", "testcenter.robotframework.testing\Testcenter.RobotFramework.Test.csproj", "{2079E935-E4C0-460D-A9F1-215E4319C85C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RobotLibraries", "RobotLibraries", "{0B0D45E9-0A08-430D-8BF5-219E15465804}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcenter.RobotLibrary.Deditec", "Testcenter.RobotLibrary.Deditec\Testcenter.RobotLibrary.Deditec.csproj", "{C04EA17A-0B86-4180-885D-9EAEC9D5D6DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcenter.RobotLibrary.Extension", "Testcenter.RobotLibrary.Extension\Testcenter.RobotLibrary.Extension.csproj", "{6E2D959E-9E66-4402-8E06-1DF0497BC92D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CI/CD", "CI/CD", "{F691C5B2-2CF5-445C-A2A1-29F480129B6E}"
    ProjectSection(SolutionItems) = preProject
        dockerfile = dockerfile
        .dockerignore = .dockerignore
        .cicd\hello-world-pipeline.yml = .cicd\hello-world-pipeline.yml
        .cicd\robotframework-release-pipeline.yml = .cicd\robotframework-release-pipeline.yml
        .cicd\scripts\build-solution-or-project.ps1 = .cicd\scripts\build-solution-or-project.ps1
        .cicd\scripts\push-nuget-package.ps1 = .cicd\scripts\push-nuget-package.ps1
        .cicd\tasks\msbuild-project.yml = .cicd\tasks\msbuild-project.yml
        .cicd\tasks\push-nuget.yml = .cicd\tasks\push-nuget.yml
    EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcenter.RobotLibrary.HCS.Roombus", "Testcenter.RobotLibrary.HCS.Roombus\Testcenter.RobotLibrary.HCS.Roombus.csproj", "{80A1F57E-39D0-4E33-B8CB-27033FBAEBF4}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Libraries|Any CPU = Libraries|Any CPU
        Release|Any CPU = Release|Any CPU
        Testing|Any CPU = Testing|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {63B8CCEF-5C50-4F25-8E6B-C623DA1BDD2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {63B8CCEF-5C50-4F25-8E6B-C623DA1BDD2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {63B8CCEF-5C50-4F25-8E6B-C623DA1BDD2F}.Libraries|Any CPU.ActiveCfg = Libraries|Any CPU
        {63B8CCEF-5C50-4F25-8E6B-C623DA1BDD2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {63B8CCEF-5C50-4F25-8E6B-C623DA1BDD2F}.Release|Any CPU.Build.0 = Release|Any CPU
        {63B8CCEF-5C50-4F25-8E6B-C623DA1BDD2F}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
        {86F3BACB-FC4D-43FC-BA20-659600C6134C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {86F3BACB-FC4D-43FC-BA20-659600C6134C}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {86F3BACB-FC4D-43FC-BA20-659600C6134C}.Libraries|Any CPU.ActiveCfg = Libraries|Any CPU
        {86F3BACB-FC4D-43FC-BA20-659600C6134C}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {86F3BACB-FC4D-43FC-BA20-659600C6134C}.Release|Any CPU.Build.0 = Release|Any CPU
        {86F3BACB-FC4D-43FC-BA20-659600C6134C}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
        {DA53C3E0-7D05-4BB7-932C-97147BFB0E4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {DA53C3E0-7D05-4BB7-932C-97147BFB0E4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {DA53C3E0-7D05-4BB7-932C-97147BFB0E4C}.Libraries|Any CPU.ActiveCfg = Libraries|Any CPU
        {DA53C3E0-7D05-4BB7-932C-97147BFB0E4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {DA53C3E0-7D05-4BB7-932C-97147BFB0E4C}.Release|Any CPU.Build.0 = Release|Any CPU
        {DA53C3E0-7D05-4BB7-932C-97147BFB0E4C}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
        {2079E935-E4C0-460D-A9F1-215E4319C85C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {2079E935-E4C0-460D-A9F1-215E4319C85C}.Libraries|Any CPU.ActiveCfg = Libraries|Any CPU
        {2079E935-E4C0-460D-A9F1-215E4319C85C}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {2079E935-E4C0-460D-A9F1-215E4319C85C}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
        {2079E935-E4C0-460D-A9F1-215E4319C85C}.Testing|Any CPU.Build.0 = Testing|Any CPU
        {C04EA17A-0B86-4180-885D-9EAEC9D5D6DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {C04EA17A-0B86-4180-885D-9EAEC9D5D6DC}.Libraries|Any CPU.ActiveCfg = Libraries|Any CPU
        {C04EA17A-0B86-4180-885D-9EAEC9D5D6DC}.Libraries|Any CPU.Build.0 = Libraries|Any CPU
        {C04EA17A-0B86-4180-885D-9EAEC9D5D6DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {C04EA17A-0B86-4180-885D-9EAEC9D5D6DC}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
        {C04EA17A-0B86-4180-885D-9EAEC9D5D6DC}.Testing|Any CPU.Build.0 = Testing|Any CPU
        {6E2D959E-9E66-4402-8E06-1DF0497BC92D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {6E2D959E-9E66-4402-8E06-1DF0497BC92D}.Libraries|Any CPU.ActiveCfg = Libraries|Any CPU
        {6E2D959E-9E66-4402-8E06-1DF0497BC92D}.Libraries|Any CPU.Build.0 = Libraries|Any CPU
        {6E2D959E-9E66-4402-8E06-1DF0497BC92D}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {6E2D959E-9E66-4402-8E06-1DF0497BC92D}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
        {6E2D959E-9E66-4402-8E06-1DF0497BC92D}.Testing|Any CPU.Build.0 = Testing|Any CPU
        {80A1F57E-39D0-4E33-B8CB-27033FBAEBF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {80A1F57E-39D0-4E33-B8CB-27033FBAEBF4}.Libraries|Any CPU.ActiveCfg = Libraries|Any CPU
        {80A1F57E-39D0-4E33-B8CB-27033FBAEBF4}.Libraries|Any CPU.Build.0 = Libraries|Any CPU
        {80A1F57E-39D0-4E33-B8CB-27033FBAEBF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {80A1F57E-39D0-4E33-B8CB-27033FBAEBF4}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
        {80A1F57E-39D0-4E33-B8CB-27033FBAEBF4}.Testing|Any CPU.Build.0 = Testing|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(NestedProjects) = preSolution
        {63B8CCEF-5C50-4F25-8E6B-C623DA1BDD2F} = {1F0EA3DB-C080-432A-9948-DF8461982CDE}
        {86F3BACB-FC4D-43FC-BA20-659600C6134C} = {1F0EA3DB-C080-432A-9948-DF8461982CDE}
        {DA53C3E0-7D05-4BB7-932C-97147BFB0E4C} = {1F0EA3DB-C080-432A-9948-DF8461982CDE}
        {2079E935-E4C0-460D-A9F1-215E4319C85C} = {0A74D269-D322-40B9-9193-AC95B08DA488}
        {C04EA17A-0B86-4180-885D-9EAEC9D5D6DC} = {0B0D45E9-0A08-430D-8BF5-219E15465804}
        {6E2D959E-9E66-4402-8E06-1DF0497BC92D} = {0B0D45E9-0A08-430D-8BF5-219E15465804}
        {80A1F57E-39D0-4E33-B8CB-27033FBAEBF4} = {0B0D45E9-0A08-430D-8BF5-219E15465804}
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {8B25855F-6BB5-44FA-8793-5F3E05270044}
    EndGlobalSection
EndGlobal
eivgtgni

eivgtgni1#

这个错误发生在我在调试/发布配置之间切换的时候。所以我猜它一定和配置有关。
不管怎样,如果我切换到我想要的配置,然后重新启动VS,它似乎工作得很好。
以防万一,有人觉得这个信息很有帮助。

相关问题