Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

Add Reference to .NET 4.5.1 class library project from ASP.NET 5 web app not working #45

Closed
johnciliberti opened this issue May 2, 2015 · 114 comments

Comments

@johnciliberti
Copy link

johnciliberti commented May 2, 2015

I am running the RC of Visual Studio Enterprise on a Windows Server 2012 R2 Virtual Machine. Folder that solution is added to is part of a git repo.
Steps to reproduce:

  1. Create new Web Application Project with ASP.NET 5 Starter Web Template
  2. Add an existing .NET 4.5.1 class library project to the solution. Project includes a reference to EF 6.1.3
  3. Add the class library project as a reference in the web application project.

Results:

  1. A reference is added to the project.json file in the web project
    "frameworks": {
    "dnx451": {
    "dependencies": {
    "Recipe05.Dal": "1.0.0-*"
    }
    }
  2. In the class library project a wrap directory is created with the folders:
  • EntityFramework
    • EntityFramework.SqlServer
    • Recipe05.Dal
      each folder has it's own project.json file with a bin configuration
      "bin": {
      "assembly": "../../obj/{configuration}/Recipe05.Dal.dll",
      "pdb": "../../obj/{configuration}/Recipe05.Dal.pdb"
      }
    • In the web project package restore fails with the following error:
      Error NuGet Package Restore failed for one or more packages. See details in the Output window.
      Restoring packages for C:\MVC6Recipes\MVC6Recipes\Chapter06\Recipe05\src\Recipe05.Dal\wrap\Recipe05.Dal\project.json
      GET https://www.nuget.org/api/v2/FindPackagesById()?Id='Recipe05.Dal'.
      OK https://www.nuget.org/api/v2/FindPackagesById()?Id='Recipe05.Dal' 1081ms
      Unable to locate Recipe05.Dal >= 1.0.0
@davidfowl
Copy link
Member

Can you show your solution layout? From the error, it looks like it can't figure out what kind of reference Recipe05.Dal is. What does the ICON show in visual studio? Is it yellow?

@johnciliberti
Copy link
Author

Yes. I get the yellow warning icon when I drill into references.
bug1

One thing that seems off is that in the wrap directory
"frameworks": {
"net451":

not
"dnx451"

Changing this has no effect however.

@davidfowl
Copy link
Member

You missed my first question. what is your solution layout. Do you have more than one global.json in your project structure? It looks like things were adding in the wrong place and the ASP.NET 5 project can't figure out the project references.

@johnciliberti
Copy link
Author

There is two global.json files but only one appeared in the solution explorer. The one in the class library project only had:
{
"projects": [
"wrap"
]
}

Interesting, if I create the ASP.NET 5 project first, then create a NEW class library project as part of the ASP.NET solution it seems to work fine.

If I include an existing library created as part of another solution, I run into issues. Does not seem to matter where the location of the referenced class library is.

Seems like in the latter case the wrap command is adding a global.json file to the class library project. This could be because I am adding a reference to a project that was created in another solution. Wrap command sees a solution folder without a global.json so it adds one.

@davidfowl
Copy link
Member

  1. Add an existing .NET 4.5.1 class library project to the solution. Project includes a reference to EF 6.1.3

That project is where on disk?

On again, can you post the solution layout at each step? I'd like to be able to reproduce this but the steps still look too vague.

@johnciliberti
Copy link
Author

I had tried it several ways. Bold indicates a solution folder, italic project folder:

1. Causes issue

Shared Library

MVC6Recipes/Shared/Mvc6Recipes.Shared.DataAccess/Mvc6Recipes.Shared.DataAccess

ASP.NET 5 Project

MVC6Recipes/Chapter06/Recipe05/src/Recipe05.Web

2. This fails also

Dal solution was created first. Closed solution. Created new Web Solution. In this case, two solution files in same directory.
MVC6Recipes/Chapter06/Recipe05/Recipe05.Dal

ASP.NET 5 Project

MVC6Recipes/Chapter06/Recipe05/src/Recipe05.Web
bug2d

3. This works Fine

In this case I had created the web app first then created the library. Library does not have it's own solution

Shared Library

MVC6Recipes/Chapter06/Recipe05/Recipe05.Dal/

ASP.NET 5 Project

MVC6Recipes/Chapter06/Recipe05/src/Recipe05.Web

@johnciliberti
Copy link
Author

Here is another way to make it fail. :-)

  1. Start with an empty solution
  2. Add Class Library project
  3. Create ASP.NET Project and select ASP.NET 5 template
  4. Build Solution
  5. Add reference to class library in web project

In this case, since you started with an empty solution, you do not get a global.json file at all.
bug2e

The work around is to remove the reference, manually delete the generated wrap directory in class library project folder and then manually create a global.json file. After that, you can add the reference and it will get you past the issue of not being able to find the package.

Even after this fix, there are other issues such as what lucamorelli mentioned in issue #8 where you get Entityframework 7 beta 4 rather then EntitityFramework 6.x. Seems like the only way to make it work is to manually add

"bin": {
        "assembly": "../../../packages/EntityFramework.6.1.3/lib/net45/EntityFramework.SqlServer.dll"
      }

To the web project's project.json file.

I think maybe you should rethink how the wrap command works for Visual Studio. Maybe you can add an option to the command line interface that would tell wrap to modify a specified project.json file rather then creating the wrap directory as it does today.

@davidfowl
Copy link
Member

In #8 he Luca was referencing EF7 and EF6

@AlexeiScherbakov
Copy link

I have this situation.
Project C depends on Project B, which depends on Project C
All them needed to be referenced in ASP.NET 5 project.

  1. I call 'dnu wrap' on Project C - it references normally [ "Project C Wrapped" ]
  2. I call 'dnu wrap' on Project B - it have trouble with reference to Project C. [ "Project B Wrapped" ]
    So I cannot reference entire chain even if I disable 'dnxcore50' compilation

@BjBlazkowicz
Copy link

I can't get this to work even how hard I try.

Issue is reproduced by the following steps:

  1. Create Empty ASP.NET 5 Application
  2. Create new .csproj class library in the same solution
  3. Reference the class library from the ASP.NET 5 app and it does not work:
    Dependency ClassLibrary2 >= 1.0.0-* Could not be resolved

Tree:
├───artifacts
│ └───obj
│ └───WebApplication3
│ └───Debug
│ └───ProjectRawReferences
│ ├───DNX 4.5.1
│ └───DNX Core 5.0
├───ClassLibrary2
│ ├───bin
│ │ └───Debug
│ ├───obj
│ │ └───Debug
│ │ └───TempPE
│ └───Properties
├───src
│ └───WebApplication3
│ ├───Properties
│ └───wwwroot
└───wrap
└───ClassLibrary2

@jcmordan
Copy link

jcmordan commented Aug 5, 2015

I resolved this,
The ASP.NET 5 web app project must have in < 4.5.2, not 4.6.

image

@sayedihashimi
Copy link
Contributor

This issue is pretty old. We have worked on improving the Add Reference support. We still have some issues related to wrap but I think the basic scenarios should work.

I'm going to close this, but if you are still having issues you can either re-open this or open a new issue with steps to reproduce.

@runxc1
Copy link

runxc1 commented Nov 10, 2015

So how is this supposed to work? I am running into some of the same problems here. I have an existing Solution with projects A, B,C,D in it and I created a new Asp.Net 5 Solution with 4 new projects and everything working fine.

I added the 4 existing projects to the Solution and saw that a project.json file was added for each of them in a /wrap folder. I then tried to reference to projects A-> D to one of the Asp.Net projects and am now getting an error.

How do I work around this error?

@nigel-dewar
Copy link

I tried this and many other things. Nothing works. Why is it so hard to add a class library and reference it from the asp.net 5 project?

@nigel-dewar
Copy link

Even if you can reference it, it breaks within a short time. For instance I checked that I could reference a class called Class1.cs from the class library in the asp.net 5 project.

But then after a short while, it is like the link breaks, And the only file you can now reference in the asp.net 5 library is that Class1.cs class. No other class you add is can be referencing.

Really weird and frustrating.

@pettys
Copy link

pettys commented Jan 7, 2016

Experiencing a similar issue - got a pretty small asp.net 5 app, pull some of my older Class Library .csproj files into the solution, try to Add Reference > Projects... so I can use those assemblies, and am getting error project.json(35,43,35,43): DNX 4.5.1 error NU1001: The dependency MyClassLib >= 1.0.0-* could not be resolved.

Pretty much everything I google for to try to learn more (like trying to figure out how the "wrap" stuff is supposed to be set up) shows this thread as a top link. :)

@runxc1
Copy link

runxc1 commented Jan 7, 2016

We probably need to test this and open a new ticket if it doesn't work inside the dotnetcli repo as dnx is dead and this may not even work the same in RC2.

@sebastianbk
Copy link

I can confirm the issue @nigel-dewar and @pettys have experienced. I experience this issue too in a brand new solution.

@jmblakl
Copy link

jmblakl commented Jan 15, 2016

Experiencing the same issue. I building a test Service Fabric App with a stateful service backend and an ASP.NET 5 web front end. I added a proj reference from the Web project to a common interfaces project I was building which defined the contract to the back end services.

The solution was created for the service fabric and then web project was added to that dir structure. Initially the project seems to work, but when I make changes to the interface in the contracts project the new contracts do not become available to the web project. Interestingly enough, it appears at design time to work; there are no syntax errors or indication that the method doesn't exist. At build time, however the output clearly show that it can't find the method and the build fails.

Directory structure:
C:/ServiceFabApp
|__ServiceFabAppProj/
|__DataServiceProj/
|__WebProj/
|__wrap/
|__global.json
|__packages
|__ServiceFabApp.sln

@RMHR
Copy link

RMHR commented Jan 18, 2016

Similar issue, trying to add a Nuget package written in a 4.6 class library, adding it as a reference adds it to the project json but says it can't resolve it. I understand ASP.NET 5 is the new and shiny but seriously this is the first thing people will be doing to port their projects - add references to their existing ones.

@kkleeberger
Copy link

Same Problem, I can't add my own .NET 4.5.1 DLL as a reference to my ASP.NET 5 Project.
CLR Type: .NET Framework

It works if I make the following changes:
#if DNX4.5.1
....
#endif

Exists for that a gobal Setting or can i remove the DNX Core Features ???

@javivalero
Copy link

I think that this issue is related with #245

@navinv789
Copy link

Same Problem not able to add my class library as reference.
Not even getting the proper error why it is not allowing to add

@jemiller0
Copy link

I noticed it's setting the following in project.json even though I had .NET Framework 4.6.1 selected when I created the ASP.NET 5 Web project.

"frameworks": {
"dnx451": { },
"dnxcore50": { }
},

I changed it to "dnx461". I was able to add the reference. However, the project won't build. It says a dependency to the library that I added couldn't be resolved. Honestly, I have no idea what is going on with ASP.NET anymore. Why is MVC 5 not the default in Visual Studio 2015? I had to install a separate download to get the templates for it. Defaulting to beta software is not a good idea. I know you guys want to push everyone into using the latest and greatest code, but, this is ridiculous. I think you should just outright call it something else and not ASP.NET. Everything is different now. It used to be the case that one could work productively in ASP.NET. It is clear that that is all changing now. You may as well use Ruby On Rails now. It has to be better than this garbage. Adding a library should be a no brainer. Yet Microsoft has convinced itself that it needs to make everything cross platform. Now there are 10 different types of libraries. This is Silverlight all over again. I don't even think Microsoft cares about it's existing developer base. All they care about is parrotting all the other open source projects. Sorry for the rant, but, I don't see how this is an improvement. It doesn't help when it comes to getting real work done as opposed to constantly shuffling the deck chairs on the Titanic. This is exactly why I always liked .NET over Java. It was a productive environment. Now we are entering the days of Maven hell on .NET.

@jemiller0
Copy link

Besides that, according to https://blogs.msdn.microsoft.com/dotnet/2015/12/09/support-ending-for-the-net-framework-4-4-5-and-4-5-1/. Support for .NET 4.5.1 is ending (already has). I have no idea why it is defaulting to that. Probably Microsoft isn't evening bothering to test on the full .NET Framework.

@runxc1
Copy link

runxc1 commented Mar 16, 2016

Yeah this is pretty much a dead thread as so much of this changes with RC2 as it will no longer be using DNX at all and will be running on the .Net CLI

@sayedihashimi
Copy link
Contributor

We are redoing p2p references to standard c# projects. We will no longer be using wrap, we will replace it with something else.

@ghost
Copy link

ghost commented Mar 29, 2016

@sayedihashimi when do you think it will be released?

@danjarvis
Copy link

👍

@rclabo
Copy link

rclabo commented May 25, 2016

I believe I only did the manual restore after the creating the reference and that is what I think fixed it. I didn't close VS and reopen it and I don't think I did any saves either but I'm less certain about that. I have tried this many times over the past few days and the issue is easy to reproduce on my setup. It happens every time with these steps:

  1. In Visual Studio, create a new ASP.NET Core Web Application
  2. To that solution Add a Windows Class Library Project
  3. In the project.json file of the web application remove the following section from dependencies:
"Microsoft.NETCore.App": {
      "version": "1.0.0-rc2-3002702",
      "type": "platform"
   },
  1. Change the framework section of the same file to this:
"frameworks": {
    "net451": {
      "dependencies": {
      }
    }
  }
  1. Save the project.json file and the auto restore happens.
  2. Use visual studio to set a reference from the web project to the Windows Class Library

Now the project.json section looks like:

 "frameworks": {
    "net451": {
      "dependencies": {
        "ExampleLib": {
          "target": "project"
        }
      }
    }

And the error appears.

I can send you whatever you want at any step.

@abpiskunov
Copy link

Just tried your steps. After i add csproj reference in step 6. , auto restore happens and everything is resolved. Does auto-restore happen for you in step 6?

Could you please do you repro steps again and see the error. After that zip whole solution with all projects and their lock and *.dg files and share with me?

@rclabo
Copy link

rclabo commented May 25, 2016

I just did the repo steps again and in step 5 when I save the project.json file I was mistaken, the auto restore does not happen, I have to do it manually. I guess this kinda explains why the auto-restore does not occur when I add the reference. I guess the thing that had me stumped is that it never occurred to me to force a Restore Packages manually when I got the error "The dependency ExampleLib could not be resolved" since its a local project in the solution. I'd be happy to zip up the whole solution and send it to you. Where should I send it?

@abpiskunov
Copy link

you can send it to my email anton.piskunov@microsoft.com.

Now let's figure out why you don't have auto restore. Could you please double check your Nuget settings under Tools\Options\NuGet Package Manager. See if you have two check boxes on top checked: "Allow NuGet to download missing packages" and "Automatically check for missing packages ...".

@rclabo
Copy link

rclabo commented May 25, 2016

Both check boxes were unchecked which may have been something stupid I did long ago when working with RC1 before I understood much about NuGet. I have now checked them. abpiskunov you have been extremely helpful. Thank You!

@jreeter
Copy link

jreeter commented May 26, 2016

Can anyone comment on whether I can reference a compiled .dll in my project.json like so:

"frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50",
      "bin": {
        "assembly": "Moserware.Skills.dll"
      }
    }
  }

I'm running the latest RC2 in OS X. When I try to reference the namespace it pulls the good ole are you missing an assembly reference?

@dmikov
Copy link

dmikov commented May 26, 2016

@jreeter Supposedly and assuming this assembly is at root with the project
the "assembly" value should actually point to assembly location

I personally wasn't able to make it work. But then again I wasn't using "netcoreapp1.0" for framework
In case the original link is gone https://github.com/dotnet/cli/blob/rel/1.0.0/TestAssets/TestProjects/TestAppWithWrapperProjectDependency/TestLibrary/project.json

@PrashanthIBM
Copy link

Hi ,

i am trying to update my project.json to use RC2, but i am not able to add the GAC assembly reference for net451 target framework .

Can you please let me know how to add gac assemblies in project.json in RC2 ?

@sayedihashimi
Copy link
Contributor

@PrashanthIBM if you want to use gac assemblies then take a look at the ASP.NET Core Web (.NET Framework) template. Your project.json should look like the one produced from that.

@peterorjeff
Copy link

peterorjeff commented May 30, 2016

we are working through plans. We don't have a specific timeline for this feature yet. We may know more in a few weeks.

@sayedihashimi or @davidfowl any ETA on when this critical issue will be fixed yet?
This information will help us decide if it's better to wait for the fix or rollback to RC1.

@PrashanthIBM
Copy link

@sayedihashimi i looked at it, but it is not able to refer the assemblies from GAC .

@JohnGalt1717
Copy link

JohnGalt1717 commented Jun 3, 2016

This is a triple whammy:

  1. You can't just a portable library that targets .NET Core 1.0 in the list of portable definitions as a dependency of a ASP NET CORE project. It both wont intellisense and won't build because it doesn't recognize the dll at all.
  2. You can't switch it to target any version of .NETStandard 1.x while leaving it as a csproj and have an ASP NET CORE project recognize it properly. (It will intellisense and compile but then the .dll is not found to load types at runtime)
  3. If you copy everything into a new .NET Core 1.0 Class library with xproj it also won't work. It even won't work if you target both .NETStandard AND .NET 45. It will work with the ASPNET Core site but it won't be recognized in the .NET project that depends upon the library.

The only way I've been able to get it to work is to point the dependant project to the .dll from the xproj after editing the project.json to include .NET 45 as well and then send the build dependency accordingly. Then it will work as a reference in the ASP NET CORE project AND will work in .NET 4.6 projects.

Please get at least xproj with .NET Standard (without special target for .NET 4.6) loading as dependancies in .NET 4.6 project and compiling without any additional runtimes or anything required. I'm OK with converting to an xproj, but using the .dll isn't kosher for me and shouldn't be required.

@barrytang
Copy link

A lot of the issues are now fixed and this is a long thread. Please try with the latest build - https://github.com/aspnet/tooling/#pre-release-builds and open new issues. Thanks!

@tonyqq
Copy link

tonyqq commented Jun 23, 2016

I just installed Update 3 RC and .NET Core 1.0.0. RC3 - VS 2015 Tooling Preview 2 (Nightly - 6/17) and I could not reference dll within Asp.Net Core app.

Really hoping it will be resolved in RTM.

@bklooste
Copy link

bklooste commented Jul 4, 2016

Same issue with Release Update3 and release core. Tooling preview 2

@jemiller0
Copy link

If that's true, that's completely pathetic. How do you have a release version of anything if something as basic as library references don't work. I ran into a separate issue where it appears that EF Core 1.0 RTM appears not to work with the full .NET Framework 4.6.1 and an ASP.NET Web Forms application. At first, I thought the problem was that I was upgrading from a previous version. Then, created a brand new project and reverse engineered the database following the instructions. Still the same problem. A version conflict on the System.Collections.Immutable library. Why even pretend this is RTM. Apparently, quality control went out the window with the switch to making everything run on Linux.

@lilpug
Copy link

lilpug commented Jul 12, 2016

"even to this day its still not working 12/07/2016"

this does need resolving the idea of RC2 and RTM was to start being able to build production grade software with the new release, we cannot build production grade software when we cannot even reference a library outside of nuget, there are 2 other threads for this issue and many more on forums, stackoverflow etc, if you would look at it, this seems to be being put on the back bone yet its something which is critically required and to be quite frank is not really giving developers confidence in migrating to your new software, you would think some form of communication to the community about issues and time scales on resolution or even acknowledgement about the issues would be wise at this point.

@veljkocasa
Copy link

Maybe they solved it. (15/07/2016)
With VS update 3 kb3165756 I am able to add reference of library project (net451) and successfully build. But I still can't find a way for "using" that assembly in a class.... Does anyone can help?

@davidmdem
Copy link

davidmdem commented Jul 15, 2016

@veljkocasa You don't mention how you were able to add the reference, but when I try through the GUI, Visual Studio gives the following message:

image

So, I don't think this was addressed. Though I don't remember that error message before. Maybe that was added?

@WolfspiritM
Copy link

WolfspiritM commented Jul 15, 2016

There is a difference in referencing a "project" (as in a Library Project that resides in the same solution as the aspnet site) and referencing already compiled DLLs.

Cross Project References always worked.
Referencing a DLL still doesn't work (without using a nuget package) since ASP.net tooling moved to the dotnet cli.

@jemiller0
Copy link

No, referencing library projects did not originally work. I have no idea if it works now or not. At the moment, I don't have time to beta test alleged release software.

@veljkocasa
Copy link

Sorry, I've meant on cross project referencing, and for me it not working...
@davidmdem I am not getting that message, but from semantic I can see it is the same issue. Try to check does .net version which you use for building library proj is the same as .net version you are including in asp core proj, but probably that is not the solution :/

@JohnGalt1717
Copy link

FYI, you cannot add a .NET standard 1.x project as a reference to a .NET 4.6.1 project. It still fails to compile properly and intellisense doesn't work. The only way to do this is to link to the resulting DLL from the bin folder of the .NET standard project which of course causes issues.

It will add it, it just wont' work right which is kind of embarrassing that this is still broken given how key to the whole "Universal" .NET core thing this is.

@chdev77
Copy link

chdev77 commented Aug 8, 2016

This is very frustrating! Created WebApi .NetCoreApp, Version=1.0. Cannot reference libraries 4.6.1. The only way is to directly reference the assembly in the bin/debug folder. This won't work well for CI builds. I've read many things on this topic and its continuously clear a Mud!.

So I created .NetCore SelfHost WebApi. Have an older 4.6.1 and cannot use it in the WebApi. This is great! The thing is, it builds with no error and the reference is added...but I cannot access it's objects from the WebApi.

Here is the project.json
`{
"dependencies": {
"BundlerMinifier.Core": "2.1.258",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"System.Diagnostics.Process": "4.1.0"
//"ULPS.Dialer.Models": "1.0.0-*"
},

"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final"
},

"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
],
"net461": {
"dependencies": {
"ULPS.Dialer.Models.dotnet461": {
"target": "project"
}
}
}
}
},

"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},

"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},

"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},

"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
`

@StarpTech
Copy link

StarpTech commented Sep 6, 2016

Hi
what is the status of this issue? I can't add references to my project. The message from @davidmdem appears. I'm using the most recent tools.

@AlexeiScherbakov
Copy link

I think it will be fixed after .csproj/MSBuild will be able to build .net core/project.json/xproj directly

According to (https://blogs.msdn.microsoft.com/dotnet/2016/07/15/net-core-roadmap/) - Q4 2016 / Q1 2017

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

No branches or pull requests