Search code examples
c#visual-studiovisual-studio-extensions

NuGet problems after moving my Visual Studio extension from old csproj to SDK-style csproj


I've switched my Visual Studio extension from old csproj format to the new SDK-style format and hoped to get everything I need with the following package references (previously I had to reference like 100 different packages in my packages.config)

<PackageReference Include="Microsoft.VisualStudio.LanguageServices" Version="3.8.0" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.0.206" />
<PackageReference Include="NuGet.VisualStudio" Version="5.8.0" />

However, while the extension builds within Visual Studio, I run into problems when building the extension with MSBuild (when restoring NuGet packages):

"C:\Path\MyExt\MyExtension.sln" (Build target) (1) ->
   "C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj" (default target) (9) ->
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.CoreUtility (>= 16.8.39) but Microsoft.VisualStudio.CoreUtility 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.CoreUtility 16.8.239 was resolved.
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.CoreUtility (>= 16.8.39) but Microsoft.VisualStudio.CoreUtility 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.CoreUtility 16.8.239 was resolved.
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Data (>= 16.8.39) but Microsoft.VisualStudio.Text.Data 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Data 16.8.239 was resolved.
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Data (>= 16.8.39) but Microsoft.VisualStudio.Text.Data 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Data 16.8.239 was resolved.
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Logic (>= 16.8.39) but Microsoft.VisualStudio.Text.Logic 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Logic 16.8.239 was resolved.
     C:\Path\MyExt\MyExt.Tests\MyExt.Tests.csproj : error NU1603: Microsoft.CodeAnalysis.EditorFeatures.Text 3.8.0 depends on Microsoft.VisualStudio.Text.Logic (>= 16.8.39) but Microsoft.VisualStudio.Text.Logic 16.8.39 was not found. An approximate best match of Microsoft.VisualStudio.Text.Logic 16.8.239 was resolved.

Indeed, the packages are not on NuGet. Is this a problem with the Microsoft.VisualStudio.SDK package? Am I doing something wrong?


Solution

  • I think the issue is related the Microsoft.CodeAnalysis.EditorFeatures package itself. And you should contact with the author.

    It's just that the problem is magnified by the new-sdk project and the true you set.

    enter image description here

    Actually, I faced the same issue in my side with even net core console project.

    You can see this:

    The nuget package has dependencies are >=16.8.39.

    enter image description here

    However, Microsoft.VisualStudio.CoreUtility does not have version 16.8.39 version but has 16.8.239. This is designed by the author. And according to the mechanism of nuget, it will install the minimum version of dependencies, but the new-sdk style project cannot automatically identify the invalid version, and this warning appears. But non-sdk style projects with packages.config will automatically install the valid version of the nuget dependencies.

    So this issue is the dual influence of the design issue of the nuget package and the particularity of the new-sdk style project. It's just magnified in this case.

    enter image description here

    ============================================

    Workaround

    To solve the issue, try these:

    1) First, disable TreatWarningsAsErrors node under Project Properties-->Build

    enter image description here

    2) manually install

    Microsoft.VisualStudio.CoreUtility 16.8.239
    
    Microsoft.VisualStudio.Text.Data 16.8.239
    
    Microsoft.VisualStudio.Text.Logic 16.8.239
    

    nuget packages additionally to update the dependencies.

    3) then enable TreatWarningsAsErrors to check.