【问题标题】:The Visual Studio for Mac compile error: Your project file doesn't list 'win' as a "RuntimeIdentifier"Visual Studio for Mac 编译错误:您的项目文件未将“win”列为“RuntimeIdentifier”
【发布时间】:2022-03-03 01:12:13
【问题描述】:

我在编译 C# 代码时遇到了一点问题。 我相信当我想将我的项目发布到 NuGet 并且我更改了我的项目的 .csproj 文件时发生了这个错误,但令人难以置信的是我在 github 上有我的项目并且我恢复了工作版本但同样的错误。

完整的错误代码:

/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Microsoft/NuGet/Microsoft.NuGet.targets(5,5): Error: Your project file doesn't list 'win' as a "RuntimeIdentifier". You should add 'win' to the "RuntimeIdentifiers" property in your project file and then re-run NuGet restore.

我实际项目的.csproj文件内容:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{D1B1F4F8-C9CF-4DC4-966D-DD7FF4683A1C}</ProjectGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>AirlyNet</RootNamespace>
    <AssemblyName>AirlyNet</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <PackOnBuild>true</PackOnBuild>
    <PackageId>AirlyNet</PackageId>
    <PackageVersion>0.1</PackageVersion>
    <Authors>Mondonno</Authors>
    <NeutralLanguage>en-US</NeutralLanguage>
    <Owners>Mondonno</Owners>
    <PackageProjectUrl>https://github.com/Mondonno</PackageProjectUrl>
    <PackageReleaseNotes>The pre-release of our wrapper</PackageReleaseNotes>
    <PackageTags>airly airly.net c# csharp</PackageTags>
    <Title>Airly.Net</Title>
    <Description>Wrapper for the Airly API written 100% in C# </Description>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug</OutputPath>
    <DefineConstants>DEBUG;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <DocumentationFile>bin\Debug\AirlyNet.xml</DocumentationFile>
    <ConsolePause>false</ConsolePause>
    <LangVersion>9.0</LangVersion>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <Optimize>true</Optimize>
    <OutputPath>bin\Release</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
    <LangVersion>9.0</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Net.Http.Formatting" />
    <Reference Include="System.Net.Http.WebRequest" />
    <Reference Include="Newtonsoft.Json">
      <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup> 
  <ItemGroup>
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="contents\common\AirlyConfiguration.cs" />
    <Compile Include="contents\common\AirlyModels.cs" />
    <Compile Include="contents\common\cache\Caches.cs" />
    <Compile Include="contents\common\handling\Errors.cs" />
    <Compile Include="contents\common\handling\Handlings.cs" />
    <Compile Include="contents\common\handling\RateLimitInfo.cs" />
    <Compile Include="contents\interactions\InteractionBase.cs" />
    <Compile Include="contents\interactions\structures\Installations.cs" />
    <Compile Include="contents\interactions\structures\Measurments.cs" />
    <Compile Include="contents\interactions\structures\Meta.cs" />
    <Compile Include="contents\rest\api\RequestModule.cs" />
    <Compile Include="contents\rest\api\RequestProviders.cs" />
    <Compile Include="contents\rest\queue\RequestQueueHandler.cs" />
    <Compile Include="contents\rest\queue\RequestQueueManager.cs" />
    <Compile Include="contents\rest\queue\RequestQueuer.cs" />
    <Compile Include="contents\rest\RestApiClient.cs" />
    <Compile Include="contents\rest\RestManager.cs" />
    <Compile Include="contents\rest\RestTypings.cs" />
    <Compile Include="contents\utils\ArrayUtil.cs" />
    <Compile Include="contents\utils\GeoUtil.cs" />
    <Compile Include="contents\utils\JsonParser.cs" />
    <Compile Include="contents\utils\Utils.cs" />
    <Compile Include="contents\Airly.cs" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="contents\" />
    <Folder Include="contents\common\" />
    <Folder Include="contents\interactions\" />
    <Folder Include="contents\rest\" />
    <Folder Include="contents\utils\" />
  </ItemGroup>
  <ItemGroup>
    <None Include="packages.config" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

我尝试添加 RuntimeIdentifier 和 RuntimeIdentifiers 但遇到同样的错误,我也尝试更改它并重新启动 VS 但同样的事情。

谢谢!

【问题讨论】:

  • 你能提供更多关于你是如何得到这个错误的信息吗?我创建了一个 C# 库项目,将 Newtonsoft.Json 包添加到其中,然后将您添加的包信息复制到第一个 PropertyGroup,但我无法重现任何构建错误。我唯一的猜测是该项目在其 obj 目录中有一个 project.assets.json 文件(这会导致问题,因为该项目有一个 packages.config 文件)应该将其删除(您可以尝试删除整个 obj 目录。跨度>
  • @MattWard 非常感谢!!!!它现在被编译并且所有单元测试都通过了,现在我尝试创建 nuget 包但向我抛出以下错误:错误 MSB4057:项目中不存在“Pack”目标(MSB4057)你能帮帮我吗?谢谢!
  • Pack 仅支持 macOS 上的 SDK 样式项目。经典项目,例如您创建的项目,不支持开箱即用的 Pack。如果您无法将其转换为 SDK 样式项目,那么您目前唯一的选择是安装 NuGet.Build.Packaging nuget 包 - nuget.org/packages/NuGet.Build.Packaging
  • @MattWard 再次感谢!现在我能够构建我的包,但出现了另一个问题:警告:未检测到目标存储库。确保源项目定义了“RepositoryUrl”属性。如果您使用的是 nuspec 文件,请确保它具有包含所需“type”和“url”属性的存储库元素。 BadRequest nuget.pkg.github.com/Mondonno 1129 毫秒错误:响应状态码不表示成功:400(错误请求)。我正在使用 github 包,我按照官方文档对其进行了配置,idk 什么不起作用。你能帮助我吗?谢谢!
  • @matt-ward 的第一条评论也对我有用,就像两个小时的头撞墙一样,谢谢伙计,不,谢谢 obj 文件夹????

标签: c# .net visual-studio nuget visual-studio-mac


【解决方案1】:

为了解决这个问题,我从我的解决方案文件夹中删除了 obj 目录
里面有东西坏了,当 VS 重新生成它时,问题就消失了

感谢 @Matt Ward 提出了这个问题 cmets。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    相关资源
    最近更新 更多