aspnet / Tooling

Issue tracker and info on Visual Studio tooling for ASP.NET
Other
256 stars 124 forks source link

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

Closed johnciliberti closed 8 years ago

johnciliberti commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago
  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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

In #8 he Luca was referencing EF7 and EF6

AlexeiScherbakov commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

image

sayedihashimi commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

jmblakl commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

I think that this issue is related with https://github.com/aspnet/Tooling/issues/245

navinv789 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

ghost commented 8 years ago

@sayedihashimi when do you think it will be released?

danjarvis commented 8 years ago

:+1:

kwaazaar commented 8 years ago

Is there at least any documentation on how to reuse existing code or assemblies? I cannot really find any.

Dotnet core documentation is getting a pretty mess anyway, as it keeps changing, but even official documentation is not updated in time. :-1:

nigel-dewar commented 8 years ago

asp.net 5 is brilliant, but I am using it for what it is good for at this stage ( front end projects ). We continue to build our APIs in .net 4.5 .

I think its a case of experimentation seeing what works and what doesn't until the day you can leave .net 4.5 behind. At this stage, I can't do this.

coderabsolute commented 8 years ago

Am facing this issue, not sure what the fix is really? Am starting a project and I really got a deadline to meet. If this is not working, can someone please propose an alternative until this is fixed?

ghost commented 8 years ago

@coderabsolute you can reference compiled dll's of your class libraries projects. This worked for me.

kneerunjun commented 8 years ago

@jemiller0 - agree , take my upvote ! - It is all Silverlight all over again! Trying to get around this issue is like a dog chasing his own tail. MongoCore C# driver needs net451 and boom , aspnet core is just adamant. Frustrating , I have spent a day trying out things - no light at the end of the tunnel.

coderabsolute commented 8 years ago

I think, I have solved this issue. I have created a brand new solution and started to add projects and all seems to work. yay! Am a happy man again!

kneerunjun commented 8 years ago

@coderabsolute : please post the project.json here

rhwilburn commented 8 years ago

I am having the same issue here. I am surprised for my project library added reference, that it is searching for it on Nuget but failing. This doesn't make the slightest bit of sense. My log shows:

Restoring packages for E:\Dev\RouteMe\1.2 webTier\RouteMeWeb\project.json
  GET https://www.nuget.org/api/v2/FindPackagesById()?id='Mobile.Common'
  OK https://www.nuget.org/api/v2/FindPackagesById()?id='Mobile.Common' 1458ms
  CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='System.Net.Sockets'
Unable to locate Dependency Mobile.Common >= 1.0.0-*

Mobile.Common is a PCL that is in the sln. It allows me to add it from my project. It then hangs for about 30 seconds (visual studio that is) and then mentions it failed to restore nuget references.

My project.json file has:

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "Mobile.Common": "1.0.0-*"
      }
    },
    "dnxcore50": {
      "dependencies": {
        "Mobile.Common": "1.0.0-*"
      }
    }
  },

Im using RC1 and have to say this wasn't the first issue I noticed. I also noticed that there was one dll missing from the default MVC project to get that to work.

leontyr commented 8 years ago

In my case, removing "dnxcore50" from project.json resolved it.

takazm commented 8 years ago

Related to this; Can i have it the other way round. I have a web api 2.2 project targeting .net 4.6.1 and a class library on same framework but created using the dnx project type. I checked the "produce output on build" and the package from the class library is there. I referenced this in my web api 2.2 project but seems not to work. I added the artifacts path to the solution package sources. Here the error i get :\ Error Unable to resolve dependency 'EntityFramework.Commands'. Source(s) used: 'nuget.org', 'myget', 'Local Entities', 'Microsoft and .NET'.
**

leontyr commented 8 years ago

Don't think you can do that. The class library (package) doesn't have dll right?

ghost commented 8 years ago

Takazm, add this reference on ef in webApi project and it may work

takazm commented 8 years ago

@AloeDream that doesnt work. install-package : Package 'EntityFramework,7.0.0' is not found in the following primary source(s): 'https://api.nuget.org/v3/index.json'. Please verify all your online package sources are available (OR) package id, version are specified correctly

takazm commented 8 years ago

@AloeDream Actually, i managed to install EF but still cant reference the package from my class library output

zemien commented 8 years ago

From my experience you would want to test this on your build server/CI server as well. I had this issue, fixed it on my machine by manually tweaking json files, committed it to source control, and it failed to build on the server. It works if I manually tweak the json on the build server as well, but that defeats the purpose of automated builds. I have since moved back to .Net 4.5.2 for my project while MS figures out a more reliable method for Core to talk to the full framework.

On Wed, 4 May 2016 at 04:41 Takaz notifications@github.com wrote:

@AloeDream https://github.com/AloeDream Actually, i managed to install EF but still cant reference the package from my class library output

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/aspnet/Tooling/issues/45#issuecomment-216589265

murpheux commented 8 years ago

Did anyone figure out the fix to this? I am having same issues and it's been about a year since this conversation started.

jemiller0 commented 8 years ago

Yeah, wait until RC2. There is something on the .NET Blog about how they’re getting rid of the stupid JSON config file and going back to XML.

Jon

From: Clement Onawole [mailto:notifications@github.com] Sent: Sunday, May 15, 2016 8:50 AM To: aspnet/Tooling Tooling@noreply.github.com Cc: Jon Miller jemiller@uchicago.edu; Mention mention@noreply.github.com Subject: Re: [aspnet/Tooling] Add Reference to .NET 4.5.1 class library project from ASP.NET 5 web app not working (#45)

Did anyone figure out the fix to this? I am having same issues and it's been about a year since this conversation started.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHubhttps://github.com/aspnet/Tooling/issues/45#issuecomment-219286919

kwaazaar commented 8 years ago

Nope, project.json will remain for now. After RTM (end of june) it will very likely be replaced by the existing csproj, which will probably need changes as well.

ghost commented 8 years ago

Please, leave that json alone! It works and it's readable and more understandable and already supported by tooling! What's really need to be changed - "wrap" and references system!

guardrex commented 8 years ago

@AloeDream Sorry ... they made the design decision, so it will be happening after RTM. We'll just have to get used to it (unfortunately).

WolfspiritM commented 8 years ago

Now that RC2 is out I can't figure out a way to Reference a Dotnet 4.5.1 Class Library via DLL. According to the project.json Documentation you can use the bin syntax to reference DLLs but it seems like this is not working with the dotnet-cli.

Is having a 4.5.1 API Library which needs to be referenced by ASP.NET really that uncommon that this whole thing got removed (or at least no replacement got added on the move to dotnet-cli)?

Referencing the Assembly in Visual Studio (which did wrap the DLL in RC1) completly fails saying that only Dotnet Framework Assemblies can be referenced in this release and others need to be nuget packages.

As a workaround it seems to work to set the Asp.NET Core project.json to net451 and add the other project (The Library) to the solution and Reference that Project from within Visual Studio via the Add Reference -> Solution window. That creates a:

  "frameworks": {
    "net451": {
      "dependencies": {
        "TestLibrary": {
          "target": "project"
        }
      }
    }
  },

This might be used to create a "wrapping" Project but this can't be the final solution to this problem. There needs to be a way to reference existing Assemblies as there was for RC1!