【问题标题】:How to solve NuGet.targets(124,5): error : Value cannot be > null. (Parameter 'folderName') error?如何解决 NuGet.targets(124,5):错误:值不能 > null。 (参数“文件夹名称”)错误?
【发布时间】:2023-03-03 12:57:01
【问题描述】:

在构建项目时出现此错误。

错误 NETSDK1004 资产文件 'J:\Test\core\fx-core\obj\project.assets.json' 未找到。运行 NuGet 包还原以生成此文件。 FxCore C:\程序 Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 234

为了解决这个问题,我在包管理器控制台中运行命令dotnet restore。但是在运行时出现以下错误。

PM> dotnet restore J:\Test\core\fx-core\FxCore.csproj(3,3):警告 MSB4011:“C:\程序 Files\dotnet\sdk\3.1.201\Current\Microsoft.Common.props" 不能 再次导入。它已经在“C:\Program 文件\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (40,3)"。 这很可能是构建创作错误。随后的导入 将被忽略。 C:\程序 文件\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3): 警告 MSB4011:“C:\Program Files\dotnet\sdk\3.1.201\Microsoft.CSharp.targets" 无法导入 再次。它已经在“J:\Test\core\fx-core\FxCore.csproj (118,3)"。这很可能是构建创作错误。这随后 导入将被忽略。 C:\程序 Files\dotnet\sdk\3.1.201\NuGet.targets(124,5):错误:值不能 空值。 (参数'文件夹名称') [J:\Test\core\fx-core\FxCore.sln] PM>

如何解决这个问题?

.Net 目标框架:4.6.1

Visual Studio:2019 (16.5.2)

项目类型:类库

更新:

根据@Lennart 请求添加 csproj 文件

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Sdk="Microsoft.NET.Sdk">
  <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>{459BF9F7-69C7-4BBD-B566-CEFB992F88D5}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>FX.Core</RootNamespace>
    <AssemblyName>FxCore</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkProfile />
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Version>1.0.2.9</Version>
    <Company>INTL FCStone</Company>
    <Authors>INTL FCStone</Authors>
    <Description>FxCore Assembly</Description>
    <Copyright>Copyright 2018</Copyright>
    <PackageReleaseNotes>version 1.0.2</PackageReleaseNotes>
    <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>TRACE;DEBUG</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Compile Remove="packages\**" />
    <Compile Remove="_CreateNewNuGetPackage\**" />
    <EmbeddedResource Remove="packages\**" />
    <EmbeddedResource Remove="_CreateNewNuGetPackage\**" />
    <None Remove="packages\**" />
    <None Remove="_CreateNewNuGetPackage\**" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Dapper, Version=1.50.2.0, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>packages\Dapper.1.50.2\lib\net45\Dapper.dll</HintPath>
    </Reference>
    <Reference Include="EasyNetQ, Version=0.63.6.463, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>packages\EasyNetQ.0.63.6.463\lib\net45\EasyNetQ.dll</HintPath>
    </Reference>
    <Reference Include="FXEntity, Version=1.0.1.12, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>packages\FXEntity.1.0.2.12\lib\net45\FXEntity.dll</HintPath>
    </Reference>
    <Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
      <HintPath>packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <HintPath>packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f, processorArchitecture=MSIL">
      <HintPath>packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Practices.Unity.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f, processorArchitecture=MSIL">
      <HintPath>packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.Configuration.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Practices.Unity.RegistrationByConvention, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f, processorArchitecture=MSIL">
      <HintPath>packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll</HintPath>
    </Reference>
    <Reference Include="Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
      <HintPath>packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll</HintPath>
    </Reference>
    <Reference Include="RabbitMQ.Client, Version=3.6.6.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce, processorArchitecture=MSIL">
      <HintPath>packages\RabbitMQ.Client.3.6.6\lib\net45\RabbitMQ.Client.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.configuration" />
    <Reference Include="System.Core" />
    <Reference Include="System.Web" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Properties\" />
    <Compile Remove="Configuration\UspHostLoginValidateResult.cs" />
    <Compile Remove="Configuration\UspHostUserRoleMenuListResult.cs" />
    <Compile Remove="Properties\AssemblyInfo.cs" />
    <Folder Include="DataAccess\" />
    <Folder Include="DataAccess\Components" />
    <Folder Include="Diagnostics\" />
    <Folder Include="Diagnostics\Components" />
    <Folder Include="NetworkProtocols\" />
    <Folder Include="Unity\" />   
  </ItemGroup>
  <ItemGroup>
    <None Include="app.config">
      <SubType>Designer</SubType>
    </None>
    <None Include="packages.config" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Connect.SSO" Version="3.5.6.1" />
    <PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.6" />
    <PackageReference Include="Dapper" Version="1.50.2.0" />
    <PackageReference Include="EasyNetQ" Version="0.63.6.463" />
    <PackageReference Include="log4net" Version="2.0.8.0" />
    <PackageReference Include="Microsoft.Practices.ServiceLocation" Version="1.3.0.0" />
    <PackageReference Include="Ninject" Version="3.2.0.0" />
    <PackageReference Include="RabbitMQ.Client" Version="3.6.6.0" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!--<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;" />
  </Target>-->
</Project>

【问题讨论】:

  • 最终,这与为这个项目/项目设置构建文件的人有关......在许多非标准情况下,某处有一个“构建”文件可以做这些事情,或者一些关于构建它的注释
  • @MarcGravell 感谢您的评论。我怎样才能继续修复它?请解释一下
  • 这就像说“我的代码有问题;我该如何解决?” - 如果不进行大量查找,我们无法回答这个问题;如果我记得,你从某个地方克隆了这个 - 我会从那里开始:是否有“如何构建”文件?有可以查看的 CI 构建吗?你能问作者吗?
  • 事情是这样的:正常/标准构建将正常工作 - dotnet restoredotnet build,你就完成了;所以不管这是什么:它不是一个正常/标准的构建;他们可以在那里做字面上的任何事情。深入了解它可能很困难,坦率地说,扔掉 csproj(只是 csproj,而不是实际代码)并从头开始重新组合起来可能更容易。但是对于这个问题没有简洁的“这就是你如何做”的答案,因为它取决于很多细节
  • 哦,任何 .targets、.props 等文件都可能导致异常

标签: c# .net nuget-package .net-4.6.1


【解决方案1】:

在 csproj 中,有一些东西跳出来:

  • 有两个 &lt;Import&gt; 看起来没必要 - 删除/评论它们
  • 没有目标框架 - 在第一个 &lt;PropertyGroup&gt; 中尝试 &lt;TargetFramework&gt;net461&lt;/TargetFramework&gt; 或类似的
  • 根元素过于复杂;可以只是&lt;Project Sdk="Microsoft.NET.Sdk"&gt;
  • 对于同样具有 &lt;PackageReference&gt; 的事物,您不需要 &lt;Reference&gt; 元素 - 您可能可以删除像“Dapper”和“Ninject”这样的事物的 &lt;Reference&gt;
    • 如果可能,最好只使用包引用

但是:通过这些更改,它应该可以工作。我的猜测是,这是一个预 SDK 项目文件,已被手动破解并调整为接近工作 SDK 项目文件的内容。


<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
  <TargetFramework>net461</TargetFramework>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{459BF9F7-69C7-4BBD-B566-CEFB992F88D5}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>FX.Core</RootNamespace>
    <AssemblyName>FxCore</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkProfile />
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Version>1.0.2.9</Version>
    <Company>INTL FCStone</Company>
    <Authors>INTL FCStone</Authors>
    <Description>FxCore Assembly</Description>
    <Copyright>Copyright 2018</Copyright>
    <PackageReleaseNotes>version 1.0.2</PackageReleaseNotes>
    <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>TRACE;DEBUG</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Compile Remove="packages\**" />
    <Compile Remove="_CreateNewNuGetPackage\**" />
    <EmbeddedResource Remove="packages\**" />
    <EmbeddedResource Remove="_CreateNewNuGetPackage\**" />
    <None Remove="packages\**" />
    <None Remove="_CreateNewNuGetPackage\**" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="FXEntity, Version=1.0.1.12, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>packages\FXEntity.1.0.2.12\lib\net45\FXEntity.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Practices.Unity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f, processorArchitecture=MSIL">
      <HintPath>packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Practices.Unity.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f, processorArchitecture=MSIL">
      <HintPath>packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.Configuration.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Practices.Unity.RegistrationByConvention, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f, processorArchitecture=MSIL">
      <HintPath>packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.configuration" />
    <Reference Include="System.Core" />
    <Reference Include="System.Web" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Properties\" />
    <Compile Remove="Configuration\UspHostLoginValidateResult.cs" />
    <Compile Remove="Configuration\UspHostUserRoleMenuListResult.cs" />
    <Compile Remove="Properties\AssemblyInfo.cs" />
    <Folder Include="DataAccess\" />
    <Folder Include="DataAccess\Components" />
    <Folder Include="Diagnostics\" />
    <Folder Include="Diagnostics\Components" />
    <Folder Include="NetworkProtocols\" />
    <Folder Include="Unity\" />   
  </ItemGroup>
  <ItemGroup>
    <None Include="app.config">
      <SubType>Designer</SubType>
    </None>
    <None Include="packages.config" />
  </ItemGroup> 
  <ItemGroup>
    <PackageReference Include="Connect.SSO" Version="3.5.6.1" />
    <PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.6" />
    <PackageReference Include="Dapper" Version="1.50.2.0" />
    <PackageReference Include="EasyNetQ" Version="0.63.6.463" />
    <PackageReference Include="log4net" Version="2.0.8.0" />
    <PackageReference Include="Microsoft.Practices.ServiceLocation" Version="1.3.0.0" />
    <PackageReference Include="Ninject" Version="3.2.0.0" />
    <PackageReference Include="RabbitMQ.Client" Version="3.6.6.0" />
  </ItemGroup>
</Project>

【讨论】:

  • 非常感谢,如果没有您的帮助,我不会解决这个问题。所以现在我能够成功运行该项目。但得到了例外。虽然我刚刚将 System.Configuration.ConfigurationManager 添加到项目 System.IO.FileNotFoundException:'无法加载文件或程序集'System.Configuration.ConfigurationManager,版本 = 4.0.3.0,文化 = 中性,PublicKeyToken = cc7b13ffcd2ddd51'。系统找不到指定的文件。'
  • @viveknuna 所以添加&lt;PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" /&gt; ? (在底部的&lt;ItemGroup&gt;
  • 在哪个项目中?我在类库中添加了,但仍然得到相同的异常
  • @viveknuna 然后两个都试试 :)
  • 我在这里也问过这个问题stackoverflow.com/questions/62793231/…用户说它不兼容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-20
  • 2017-10-27
  • 1970-01-01
  • 2019-12-23
  • 1970-01-01
  • 2012-10-23
相关资源
最近更新 更多