Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Wrong reference path in NETStandard.Library.targets #708

Closed
weshaggard opened this issue Apr 16, 2018 · 40 comments · Fixed by #710
Closed

Wrong reference path in NETStandard.Library.targets #708

weshaggard opened this issue Apr 16, 2018 · 40 comments · Fixed by #710
Assignees

Comments

@weshaggard
Copy link
Member

@cannehag commented on Thu Apr 12 2018

After installing NetStandard.Library 2.0.2, a lot of warning occur.

NetStandard.Library.targets 2.0.2 have
<Reference Include="$(MSBuildThisFileDirectory)\ref\Microsoft.Win32.Primitives.dll...
According to documentation MSBuildThisFileDirectory will include a final slash, thus giving a path with double slash and the error message
The referenced component 'C:\Users\xxx.nuget\packages\netstandard.library\2.0.2\build\netstandard2.0\ref\Microsoft.Win32.Primitives.dll could not be found'

Version 2.0.1 does not have this issue since the targets file is including *.dll from another path


@elementalpete commented on Mon Apr 16 2018

I experienced the same issue after upgrading (path in warning message contains a double slash, actual path has only a single slash). Downgrading to 2.0.1 solved the issue for now.

@weshaggard
Copy link
Member Author

@cannehag @elementalpete his cause any issue beyond a warning?

@ericstj
Copy link
Member

ericstj commented Apr 16, 2018

It would also help to understand if you get the same warning from the command line, or is it only in Visual Studio. Please share more information about where you are seeing the warning and what product you are using.
I've tried to reproduce this and cannot do so using the dotnet CLI on Windows or Mac, MSBuild on windows, nor in VS2017. I'm using a netstandard2.0 project and updating the package reference manually to 2.0.2.

@elementalpete
Copy link

elementalpete commented Apr 16, 2018

I am running Visual Studio 2017 (updated to latest version today, 4/16/2018). This is on a Windows Service targeting .NET Framework 4.6.1 that references a .Net Standard class library. I see the warnings in the Error List and also under the project References in Solution Explorer, but after upgrading again, I had to play around to get the warnings to reappear (I think that drilling into References as shown on the right of the screen capture is what triggered them to reappear in Error List). I'm not sure where to look in the command line as this is not a .Net Core project... I am attaching a screen shot that shows the issue, including the location of the double slash.

As far as I can tell, these are only pesky warnings - I believe that my project is still running fine.

screen-capture

@ericstj
Copy link
Member

ericstj commented Apr 16, 2018

Looking at that path it appears to be occurring from your .NET4.6.1 project which uses packages.config (I'm guessing based on the path that uses a local packages folder with the package version in the folder name). Is that correct? Can you see if NuGet made any changes to the project file? Where did you update the package: the .netstandard project or the .net 4.6.1 project or both?

The odd thing is that those targets shouldn't add any references in a .NET 4.x project, due to the condition:

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'">

But that appears to be what's happening here. It's actually similar to dotnet/project-system#1542 which makes sense: desktop projects use the old project system. I did change the way these items are defined, and its possible we got lucky with this behavior in 2.0.1.

I'm pretty certain the double \\ is a red herring; msbuild handles this. I believe the cause of the warning is that the old project system does a fast-pass on the project ignoring conditions and comes up with references that aren't satisfied when doing the build of the project.

@elementalpete
Copy link

Yes, I'm not overly worried at this point - I was investigating an unrelated issues as was alarmed by all of the "file not found" warnings, but it seems to be the warning that is inaccurate, not the build process. I just commented since the issue was not reproducible. I performed the update from NuGet package manager, and updated all (stable only) packages in the solution, so the update occurred in both projects at the same time.

The packages.config and the MyProject.csproj seem to be different only in the version numbers. I can't figure out how to do a compare on the project file because .csproj files can't be viewed while the project is loaded, but this seems to be the relevant part:

...
<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('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets'))" />
    <Error Condition="!Exists('..\packages\NETStandard.Library.2.0.2\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.2\build\netstandard2.0\NETStandard.Library.targets'))" />
  </Target>
  <Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" />
  <Import Project="..\packages\NETStandard.Library.2.0.2\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.2\build\netstandard2.0\NETStandard.Library.targets')" />
</Project> 
...
<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('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets'))" />
    <Error Condition="!Exists('..\packages\NETStandard.Library.2.0.1\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.1\build\netstandard2.0\NETStandard.Library.targets'))" />
  </Target>
  <Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" />
  <Import Project="..\packages\NETStandard.Library.2.0.1\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.1\build\netstandard2.0\NETStandard.Library.targets')" />
</Project>

And here is the compare on the packages.config:
differences

@bslatner
Copy link

bslatner commented Apr 17, 2018

I'm experiencing this same issue. Nothing from command line builds, it's only in Visual Studio. And even in VS, the project(s) still compile and run without issue. It's just annoying from a visual perspective.

@ericstj
Copy link
Member

ericstj commented Apr 17, 2018

Ok, I have a consistent minimal repro:

  1. Install NETStandard.Library 2.0.2 directly in a .NETFramework project (old style project, not using SDK project) using either packagereference or packages.config.
  2. Unload and reload the project.

It is indeed the project system doing an evaluation of the project without evaluating conditions. Choose/when seems to be a trick to short circuit.

To workaround you may change the targets inside the package from

  <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'">
    ...
  </ItemGroup>

to

  <Choose>
    <When Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'">
      <ItemGroup>
        ...
      </ItemGroup>
    </When>
  </Choose>

I'll submit a PR for this workaround.

@Sc0tTyXL
Copy link

Same issue here.

I tried deleting the references but that's only a temporary fix. They come after a while (probably when running a Package-Update)

@ericstj
Copy link
Member

ericstj commented Apr 19, 2018

Reopened for release branch fix.

@rclabo
Copy link

rclabo commented Apr 25, 2018

I'm having this same issue. My libraries exhibiting this behavior are targeting Full Framework 4.6.1. As others have said, the solution still compiles and appears to run fine but it's disconcerting seeing all those warnings. If I delete the bogus references they end coming back the next time I open the solution.

Screenshot of the broken references:

image

Screen shot of all the warnings:

image

This appears to be the relevant part of my .csproj file for one of the class library projects:

    <Import Project="..\packages\NETStandard.Library.2.0.2\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.2\build\netstandard2.0\NETStandard.Library.targets')" />
    <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('..\packages\NETStandard.Library.2.0.2\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.2\build\netstandard2.0\NETStandard.Library.targets'))" />
    </Target>

Is there a way for me to edit this .csproj to make all the warnings go away?

@ericstj
Copy link
Member

ericstj commented Apr 25, 2018

See my comment here: #708 (comment)

Alternatively you can pick up NETStandard.Library 2.0.3 from https://dotnet.myget.org/F/dotnet-core/api/v3/index.json which has the fix. We'll be publishing to NuGet.org shortly.

@weshaggard
Copy link
Member Author

This if fixed in the release branch now so closing.

@ericstj
Copy link
Member

ericstj commented May 7, 2018

NETStandard.Library 2.0.3 is now on nuget.org.

@EmilAlipiev
Copy link

how do we get that for shared projects in xamarin forms ? I am able to install it on xamarin android, uwp and ios but I am not able to do it for shared project. it always stands "blocked by project" and when I try to change directly editing the proj file, it tell me that my current net standard installation doesnt support it. but i have the latest version of VS2017 and net standard and net core installed.

@david-chambers
Copy link

@ericstj Is there any way to workaround this in a UWP application that uses Microsoft.NETCore.UniversalWindowsPlatform 6.1.4? This package has a dependency on NETStandard.Library 2.0.2.

@ericstj
Copy link
Member

ericstj commented May 17, 2018

/cc @zamont
Yes, just directly install NETStandard.Library 2.0.3.

@rubenc57
Copy link

Version 2.0.3 gives same 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\NETStandard.Library.2.0.1\build\NETStandard.Library.targets."

@zacharycmontoya
Copy link

@rubenc57 can you please close/reopen your solution and then rebuild the project? I think this will help VS understand that it needs to refresh its build targets that come from the NuGet packages.

@rubenc57
Copy link

@zamont I already did that and same error

@zacharycmontoya
Copy link

If it's not too bothersome for you, could you clear your NuGet cache by doing

Tools->NuGet Package Manager->Package Manager Settings->Clear All NuGet Cache(s)

and then rebuild?

@ericstj
Copy link
Member

ericstj commented May 18, 2018

Actually it sounds like you have automatic restore disabled. Either enable it in package manager settings or right click the solution node in vs and choose restore.

@rubenc57
Copy link

@zamont "Clear All NuGet Cache(s)" --> Same error
@ericstj "right click the solution node in vs and choose restore" --> nothing to restore, Same error

@ericstj
Copy link
Member

ericstj commented May 18, 2018

....\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets.

Interesting. It actually looks like something is confused between packages.config and packagereference.
That path is the place where nuget would install for a package.config based project. What type of project is this? It looks like it has some cruft in it from an old package.config install. If you are now using packagereference, just delete those old imports. If you're unsure please share the project file (and packages.config if present).

@rubenc57
Copy link

rubenc57 commented May 20, 2018

Problem was on project file... I removed old imports and worked

Thanks for the help

@ericstj
Copy link
Member

ericstj commented May 21, 2018

I see, yeah that can happen with the old package.config based nuget. It's quite fragile since it mixes user state with package state (writing to the project file) then stores install state in packages.config. If any of these views is out of sync then it'll do the wrong thing on an upgrade, or if it can't find the data it previously wrote in the project it will abandon it, etc etc. I'd really recommend moving to PackageReference if you can.

@dominikjeske
Copy link

I have same error on UWP (for Windows IoT) application project created in VS 2017 15.7.2 with UWP nuget 6.1.4 (I tried also 6.2 preview). I have referenced .NET Standard 2.0.3 assemblies and have warnings like below. I tried to clear nuget references but it not helped and all .net standard libs have csproj not packages.config.

netstandard_error

@ericstj
Copy link
Member

ericstj commented May 29, 2018

After updating to NETStandard.Library 2.0.3 you may need to unload and reload the solution in Visual Studio as it is the project system that has the stale state. I believe @zamont and @HollyAM are working on an update to the UWP package.

@dominikjeske
Copy link

How can I unload solution - you mean VS restart? I can unload project - I tried to unload every project and reload again with clean nuget cache and restart VS and nothing is helping.

@pmarangoni
Copy link

pmarangoni commented May 29, 2018

After updating NETStandard.Library to version 2.0.3 I get this error when trying to build my ASP.NET MVC project:

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\NETStandard.Library.2.0.1\build\NETStandard.Library.targets.

If I try to uninstall 2.0.3 and install 2.0.2, I get the same problem. I have to revert back to 2.0.1.

Very frustrating.

@dominikjeske
Copy link

I fixed the problem by deleting .vs folder from solution. I restarted VS two time and problem is not repeating.

@HollyAM
Copy link

HollyAM commented Jun 1, 2018

If you install UWP 6.1.5, you will get the fix. You can get it on nuget: Microsoft.NETCore.UniversalWindowsPlatform

@pmarangoni
Copy link

I tried deleting the .vs folder from solution, but problem was still happening.

@dominikjeske
Copy link

Hmm I also updated to UWP 6.1.5 so maybe that was the magic trick not .vs :)

@dev8546
Copy link

dev8546 commented Jun 4, 2018

I am also facing the same issue with one of the Xamarin android project "If I try to uninstall 2.0.3 and install 2.0.2, I get the same problem. I have to revert back to 2.0.1." Nothing worked other than the solution mentioned by @pmarangoni (VS2017 Community edition)

@ericstj
Copy link
Member

ericstj commented Jun 4, 2018

Package 2.0.3 resolves the warnings in the IDE. Here are the sorts of things you must do when updating the package:

  1. Restore the project after the update.
  2. If using packages.config make sure to save the project file after this update.
  3. Close and reload the solution (from the file menu choose Close solution, then reopen). Alternatively just close and reload VS. This is an unfortunate requirement for any project using the old VS Project system with packages that update targets files.

If anyone is still seeing the problem after the following the steps above, please open a new issue with repro steps and we will look into it.

@pmarangoni
Copy link

I'm still seeing this problem even after reloading solution. Frustrating.

@ericstj
Copy link
Member

ericstj commented Jun 20, 2018

If you're still seeing a problem please open a new issue with full details of repro steps. I'll be happy to look into it, but I need more data. Thanks.

@pmarangoni
Copy link

#777

@AndrewPlusTen
Copy link

I deleted this code in .vbproj file and the error went away.

<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('..\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets'))" /> </Target> <Import Project="..\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets')" />

BlythMeister added a commit to BlythMeister/FAKE that referenced this issue Sep 25, 2018
I keep running into dotnet/standard#708 and this is apparently fixed in 2.0.3
@JISexton
Copy link

And somehow we call this progress....

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.