如何解决 NuGet.targets(124,5): error : Value cannot be > null. (Parameter 'folderName') 错误?

4

我在构建项目时遇到了以下错误:

错误 NETSDK1004:找不到资源文件“J:\Test\core\fx-core\obj\project.assets.json”。请运行NuGet包还原以生成此文件。FxCore C:\Program 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:\Program Files\dotnet\sdk\3.1.201\Current\Microsoft.Common.props”无法再次导入。 它已经在“C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (40,3)”中导入。 这很可能是一个构建作者错误。将忽略此后续导入。 C:\Program Files\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:\Program Files\dotnet\sdk\3.1.201\NuGet.targets(124,5):错误:值不能为空。(参数“folderName”)[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>

1
最终,这与为该项目/项目设置构建文件的人有关...在许多非标准情况下,某个地方会有一个“构建”文件来执行操作,或者有一些有关构建的说明。 - Marc Gravell
1
事情是这样的:一个正常/标准的构建将会“顺利运行”- dotnet restoredotnet build,然后你就完成了;所以无论这是什么:“它不是一个正常/标准的构建”;他们可能在里面做任何事情。找到问题的根源可能很难,坦白地说,从头开始重新组合一个新的csproj(只是csproj,而不是实际代码)可能更容易。但是对于这个问题没有简洁的“这是如何做到的”答案,因为它“取决于很多细节”。 - Marc Gravell
1
哦,任何 .targets、.props 等文件都可能导致奇怪的问题。 - Marc Gravell
这是否与我机器上安装的 .net 框架有关?@MarcGravell - Vivek Nuna
@MarcGravell,那么解决这个问题最简单的方法是什么? - Vivek Nuna
显示剩余13条评论
1个回答

3
在 csproj 文件中,有几个要点需要注意:
  • 有两个看起来不必要的 <Import> - 可以删除或注释掉
  • 没有指定目标框架 - 在第一个 <PropertyGroup> 中尝试添加类似 <TargetFramework>net461</TargetFramework> 的内容
  • 根元素过于复杂;可以简化为 <Project Sdk="Microsoft.NET.Sdk">
  • 对于已经有 <PackageReference> 的项目,不需要再添加 <Reference> 元素 - 如 "Dapper" 和 "Ninject" 等,可以尝试将它们删除
    • 如果可能,最好只使用包引用
但是:通过这些更改后应该能够正常工作。我猜想这可能是一个预先配置过的非 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>

1
@viveknuna 所以要添加 <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" /> 吗?(在底部的 <ItemGroup> 中) - Marc Gravell
在哪个项目中?我已经添加到类库中,但仍然收到相同的异常。 - Vivek Nuna
1
@viveknuna 那就都试试吧 :) - Marc Gravell
我在这里也问了这个问题 https://stackoverflow.com/questions/62793231/could-not-load-file-or-assembly-system-configuration-configurationmanager-vers?noredirect=1#comment111043513_62793231 用户们说它不兼容。 - Vivek Nuna
但是,这又将是一个问题,为什么我们需要在两个应用程序中都添加引用。 - Vivek Nuna
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接