How to diagnose projects load issues in solution? (has errors -> MSB18 / has missing dependencies)

Hi!

We have a solution with 328 projects in it. And we have global.json file next to the solution.

{
  "sdk": {
    "version": "2.1.402"
  }
}

When I change it to

{
  "sdk": {
    "version": "6.0.0",
    "rollForward": "latestMinor",
    "allowPrerelease": false
  }
}

Then in rider when I open solution, error next to one of the projects appears (has errors), when I click on has errors i see:

[MSB4018] The "ResolvePackageDependencies" task failed unexpectedly. System.ArgumentException: Invalid framework version '2.0/win7-x64'.

at NuGet.Frameworks.NuGetFramework.ParseFrameworkNameParts(IFrameworkNameProvider mappings, String[] parts, String& framework, Version& version, String& profile)

at NuGet.Frameworks.NuGetFramework.ParseFrameworkName(String frameworkName, IFrameworkNameProvider mappings)

at NuGet.Frameworks.NuGetFramework.Parse(String folderName, IFrameworkNameProvider mappings)

at Microsoft.NET.Build.Tasks.ResolvePackageDependencies. b__48_5(String tg)

at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()

at System.Linq.Enumerable.Contains[TSource](IEnumerable`1 source, TSource value, IEqualityComparer`1 comparer)

at System.Linq.Enumerable.Contains[TSource](IEnumerable`1 source, TSource value)

at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.c__DisplayClass48_1. b__3(IAssetsLogMessage log)

at System.Linq.Enumerable.WhereListIterator`1.MoveNext()

at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)

at Microsoft.NET.Build.Tasks.ResolvePackageDependencies. g__GetPackageDiagnosticLevel|48_0(LockFileLibrary package)

at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageAndFileDefinitions()

at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.ExecuteCore() at Microsoft.NET.Build.Tasks.TaskBase.Execute()

at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()

at Microsoft.Build.BackEnd.TaskBuilder. d__26.MoveNext() at (195:5)  

Target: RunResolvePackageDependencies

Task: ResolvePackageDependencies

Task ResolvePackageDependencies is located in C:\Program Files\dotnet\sdk\6.0.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets

So I suppose it uses msbuild from SDK instead of msbuild in MsBuildTools. (C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin).

 

Also, a lot of other projects start showing "has missing dependencies".

How do I diagnose what causes it? Specifically:

1. [MSB4018] The "ResolvePackageDependencies" task failed unexpectedly. 

2. "has missing dependencies" next to other projects in solution? 

 

---

Bonus:

csproj:

<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Company.Product.All.sln))\.props\SharedLibrariesSdkStyle.props" />

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Company.Product.All.sln))\.props\StyleCop.props" />


  <ItemGroup>
    <PackageReference Include="Microsoft.Rest.ClientRuntime">
      <Version>2.3.2</Version>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json">
      <Version>13.0.1</Version>
    </PackageReference>
    <PackageReference Include="System.IO">
      <Version>4.3.0</Version>
    </PackageReference>
    <PackageReference Include="System.Runtime">
      <Version>4.3.1</Version>
    </PackageReference>
  </ItemGroup>
</Project>

ShareLibrarySdkStyle.props

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0">
  <Import Project="DotNetCore.props" />
  <PropertyGroup>
    <OutputRoot>$(SolutionDir)\Build\$(Configuration)</OutputRoot>
    <OutputPath>$(OutputRoot)\Shared</OutputPath>
    <PlatformOutputPath>$(TargetFramework)\$(RuntimeIdentifier)</PlatformOutputPath>
  </PropertyGroup>
</Project>

DotNetCore.props

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0">

  <PropertyGroup>
    <TargetFramework>netstandard20</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <LangVersion>8.0</LangVersion>

    <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
    <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
    <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>

    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>

    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildThisFileDirectory)..\</SolutionDir>
    <OutputRoot>$(SolutionDir)\Build</OutputRoot>
    <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>

    <WarningsAsErrors />
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
    <WarningLevel>4</WarningLevel>
    <NoWarn />
    <FileAlignment>512</FileAlignment>
    <ErrorReport>prompt</ErrorReport>
  </PropertyGroup>

  <PropertyGroup>
    <CodeAnalysisRuleSet>$(SolutionDir)\Product.ruleset</CodeAnalysisRuleSet>
    <CodeAnalysisIgnoreGeneratedCode>true</CodeAnalysisIgnoreGeneratedCode>
  </PropertyGroup>

  <ItemGroup>
    <AdditionalFiles Include="$(SolutionDir)\stylecop.json">
      <Visible>false</Visible>
    </AdditionalFiles>
  </ItemGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <Prefer32Bit>false</Prefer32Bit>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <Prefer32Bit>false</Prefer32Bit>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <DefineConstants>TRACE</DefineConstants>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Company.Product.All.sln))\Include\Company.Product.AssemblyInfo.global.cs">
      <Link>Properties\CommonAssemblyInfo.cs</Link>
    </Compile>
  </ItemGroup>

</Project>

 

StyleCop.props

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <ItemGroup>
    <Compile Include="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Company.Product.All.sln))\Include\GlobalSuppressions.cs">
      <Link>Properties\GlobalSuppressions.cs</Link>
    </Compile>

    <AdditionalFiles Include="$(SolutionDir)\.settings\Product.CodeAnalyzer.Settings.json" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Company.Product.Analyzers.CodeAnalyzer">
      <Version>1.3.7</Version>
    </PackageReference>
    <PackageReference Include="StyleCop.Analyzers">
      <Version>1.1.118</Version>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
</Project>

2 comments
Comment actions Permalink

Ok, an update:

1. [MSB4018] The "ResolvePackageDependencies" task failed unexpectedly. 

I've resolved it by packing this project as a nuget dependency. Not Ideal, but error is gone.

 

2. "has missing dependencies" next to various projects in solution

I've opened the solution in Visual Studio 2022 -> it loads all the solution structure and all the projects in solution without errors.

I suppose, it works in Visual Studio because VS and Rider uses different MSBuild for restore under the hood.

VS = C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe

Rider = Autodetects C:\Program Files\dotnet\sdk\6.0.302\MSBuild.dll

I've tried to change the MSBuild version in Rider settings but still get the error.

 

Is there anything I can do on my side  to investigate why some projects show error in Rider but load without errors in Visual Studio? 

0
Comment actions Permalink

Oh, I finally figured it out.......

It's caused by incorrect spelling of target framework. 

I was using netstandard20 (wrong), correct is: netstandard2.0

After adding the dot, problem resolved.

 

Related task in youtrack: https://youtrack.jetbrains.com/issue/RIDER-75648/netstandard20-is-not-parsed-as-a-valid-target-framework-by-Rider

0

Please sign in to leave a comment.