14
votes

I am trying to install/restrore Microsoft.Net.Compilers.1.0.0 in VS 2017 using Nuget Package Manager. In the output it shows restore completed. however when i check the packages folder i dont see Microsoft.Net.Compilers folders. And beacuse of that i get error

Severity Code Description Project File Line Suppression State Error This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ....\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props. XXXXX\Src\Api\Api.csproj 296

In csproj file there is a line at the top

<Import Project="..\..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />

Background
This issue is occurring in Web API project with target framework 4.6.2. I also have NET Standard 1.4 library that i want to share with different types of .NET application. When i add reference of NET Standard Library to Web API project i got missing dependencies issues. So as per the suggestion i edited .csproj file and added

  <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

That fixed the missing dependencies issue.

Then i deleted package.config file, removed all packages from packages folder and added back all the packages (except i could not add Microsoft.Net.Compilers). The package reference is now in .csproj file

There SO post here, however in my case Microsoft.Net.Compilers does not even getting restored to packages folder. VS 2017 shows restored is complete but i don't know where its actually coping the files. (unless the folder name is different than Microsoft.Net.Compilers)

My original package.config file has this line

<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net462" developmentDependency="true" />

now in .csproj file i have

   <PackageReference Include="Microsoft.Net.Compilers">
      <Version>1.0.0</Version>
    </PackageReference>

UPDATE 1
So it looks like when packagereference is enabled nuget will install the packages at C:\Users\{username}\.nuget\packages folder

that means i need to update csproj file with correct relative path.

What would be the relative path here for packages folder?

3
Since I had trouble with this nuget, I have just removed it from project file, and now it compiles.subrob sugrobych

3 Answers

14
votes

Since setting the Package Management Format to PackageReference installs the packages to global nuger folder that is C:\Users\{username}\.nuget\packages i had to edit csproj file update the following lines

top of csproj

<Import Project="$(UserProfile)\.nuget\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('$(UserProfile)\.nuget\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
  <Import Project="$(UserProfile)\.nuget\packages\Microsoft.Net.Compilers\2.1.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props')" />

and then update the following lines at the bottom of csproj

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(UserProfile)\.nuget\packages\Microsoft.Net.Compilers\2.1.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '$(UserProfile)\.nuget\packages\Microsoft.Net.Compilers\2.1.0\build\Microsoft.Net.Compilers.props'))" />
    <Error Condition="!Exists('$(UserProfile)\.nuget\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '$(UserProfile)\.nuget\packages\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform\1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
  </Target>

All of this is just to reference NET Standard 1.4 project into .NET 4.6.2. very annoying!!

3
votes

@LP13's answer got me pointed into the correct direction. Although I had to do something different.

My .csproj file have 2 references to Microsoft.Net.Compliers. One for 2.9.0 (current one I'm using) and 1.2.1 (old version).

At the top of the file I commented out the 2 Import Project lines that referenced:

  • Import Project=".\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1 ...

  • Import Project=".\packages\Microsoft.Net.Compilers.1.2.1 ...

At the bottom of the file, do the same in the Error Condition entries for the same refrences:

  • Error Condition="!Exists('.\packages\Microsoft.Net.Compilers.1.2.1...
  • Error Condition="!Exists('.\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1' ...
2
votes

In my case I had downloaded a project from GitHub which did not include the full sln, but was just a single folder with .csproj and packages folder on the same level.

In this case I simply had to replace "..\packages\" with ".\packages\" in the .csproj file. I assume the owner of the GitHub repo decided to only upload the project folder, but didn't recompile to test before uploading... maybe?