Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.net Core App 1.1 doesn't resolve external .net standard libs #4772

Closed
gkhanna79 opened this issue Mar 8, 2017 · 5 comments
Closed

.net Core App 1.1 doesn't resolve external .net standard libs #4772

gkhanna79 opened this issue Mar 8, 2017 · 5 comments

Comments

@gkhanna79
Copy link

Opening on behalf of @gentlehag who posted this at https://github.com/dotnet/coreclr/issues/10037 originally:

I had a project in .net core 1.0 which is refrencen a standard 1.4 library. this works fine.

No i tried to switch to .net core 1.1 an I get AssemblyNotFoundExceptions.

To isolate the problem I tested the same thing by creating a new project with the released VS2017

Fir this I created a solution with 2 projects. A .net core 1.1 host (console) and a .net standard 1.4 class library.

I changed the standard lib to 1.6

Then I add the reference to the client as project refrence in the core console project.

Then at runtime i get the exception that the assembly of the client is not found. And this at the first place i use a type of the .net standard assembly so my test console looks as trivial as this:

class Program
{
static void Main(string[] args)
{
var foo = new Class1();
When I switch the host project to .net core 1.0 everything is working fine.

I published a sample here: https://github.com/Gentlehag/coreapp11bug

Is this expected behavior ?

Which .net standard library version should work with .net core 1.1 ?

PS: I also posted here:
http://stackoverflow.com/questions/42677625/net-core-app-1-1-doesnt-resolve-external-net-standard-libs

@gentlehag shared the following data as well (at https://github.com/dotnet/coreclr/issues/10037#issuecomment-285152712):

Just recognized that it works when i put the dependency ina nuget package. I uipdated the repo with a second console project which uses the nuget package and which is always working

Ok Summarized: It failes 100% in my tests when both are true

starting from within vs 2017 with F5
the reference is set to a .net standard file ( not project reference)
And it always wroks when:

i use the dotnet command line to build and run. regardless wether i have file or project references
-- OR --
When I put the .netstandard lib in a nuget package
So shortcut to reproduce the bug:
Create .net core 1.1 console app and file reference a .net standard (1.4 /1.6) assembly

Per @eerhardt, NuGet isn't writing the correct information into the project.assets.json file.

CC @rrelyea

@emgarten
Copy link
Member

emgarten commented Mar 9, 2017

Create .net core 1.1 console app and file reference a .net standard (1.4 /1.6) assembly

NuGet doesn't read <Reference> items for dlls, it just deals with projects and packages.

Trying this locally I'm able to restore this fine and the project shows up in the project.assets.json file.

It is expected that when removing the project reference and adding a direct dll reference that this would no longer show up in the assets file.

@gentlehag can you provide some clear repro steps on how to get this to fail? The output project.assets.json file does not match what you have checked in, or your mention of file references.

EDIT: I think I was able to repro this with consoleapp1:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="..\Service\bin\Debug\netstandard1.6\Service.dll" />
  </ItemGroup>
</Project>

output:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Service, Version=1.0.0.0, Culture
=neutral, PublicKeyToken=null'. The system cannot find the file specified.
   at ConsoleApp1.Program.Main(String[] args)

@BoasE
Copy link

BoasE commented Mar 9, 2017

I'm also not sure wether this is a nuget bug. Is Nuget handling file references?

Your project xml looks exactly like the steps i have to reproduce the bugs manually:
So for this way:

  • open the Existing ConsoleApp1 form the sample repo
  • remove the reference to the service .
  • Also remove the service project from the solution
  • re add it to the precompibled service.dll
  • Compile and Run (F5)

It is also reproduceable when you fo:

  • in vs2017 Create a new .net core app in a fresh new solution
  • Add a file reference to the precompile .net standard library
  • Compile and Run (f5)

=> Then I get FileNotFound Exception

PS: When I wrap up the Service.dll in a NuGetPackage and reference this nugetpackage instead of the file reference everything is working fine.

@eerhardt
Copy link

eerhardt commented Mar 9, 2017

It looks like this issue can be closed. NuGet is doing the right thing in this scenario. Since it is a <Reference> to an assembly on disk, it is not expected that NuGet write this information into the project.assets.json file.

We do need to consider how dotnet pack handles this scenario for .NET Core 2.0. The other dotnet commands handle this scenario in 2.0. See dotnet/sdk#120

@emgarten
Copy link
Member

emgarten commented Mar 9, 2017

@Gentlehag you should use the workaround of adding the dll to a nupkg for now.

@emgarten emgarten closed this as completed Mar 9, 2017
@bgever
Copy link

bgever commented Aug 8, 2017

NuGet doesn't read <Reference> items for dlls, it just deals with projects and packages.

I had this issue with a .NET Framework 4.6.1 library which I converted to multi-target .NET Standard. It uses C# dynamics, and requires Microsoft.CSharp.

Before:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>

</Project>

After:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard1.6;net461</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
  </ItemGroup>

</Project>

This removes the <Reference> which isn't supported.

Hope this can help someone having the same problem.

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

No branches or pull requests

5 participants