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

Scenario: enable references to any assembly on disk #120

Closed
2 of 3 tasks
eerhardt opened this issue Sep 2, 2016 · 20 comments · Fixed by #876
Closed
2 of 3 tasks

Scenario: enable references to any assembly on disk #120

eerhardt opened this issue Sep 2, 2016 · 20 comments · Fixed by #876
Labels
Milestone

Comments

@eerhardt
Copy link
Member

eerhardt commented Sep 2, 2016

.NET Core projects never supported referencing an assembly sitting on disk. MSBuild support this more naturally.

To enable this we need to ensure:

  • The assembly is copied to the build and publish folders.
  • The assembly is added to the .deps.json file.
  • How does "dotnet pack" handle this scenario?
@Petermarcu
Copy link
Member

We should get this fixed when we are ready to support .NET Standard 2.0. People will want to reference lots of libraries that shipped well before NuGet was a thing and we should get out of their way :)

@JohnGalt1717
Copy link

It needs to happen sooner than that. People already want to reference .net standard 1.3 dlls in .net core web apps. The use case is an internal library of utilities or a client library for a rest service that is used in multiple client libraries and websites.

You don't want the actual projects cross loaded across repos because that causes continuous deploy issues. Instead you'll use a libs folder in each project and reference them.

(And this is still broken in the latest VS.net 2017 RC with csproj in all but the trivial case. As soon as there are any nuget dependencies like json.net it fails)

@srivatsn srivatsn modified the milestones: 1.1, 1.0 RTM Jan 27, 2017
@JohnGalt1717
Copy link

This is still broken in VS.NET 2017 RC3 FYI.

@NTaylorMullen
Copy link
Contributor

This scenario breaks MVC applications. Aka, if a user attempts to utilize a referenced assembly from disk in their View the view fails to compile because the deps.json doesn't have an entry for the referenced assembly. Looks like there's a decent amount of feedback from the community around this: https://developercommunity.visualstudio.com/content/problem/17274/razor.html

@TheRealPiotrP
Copy link
Contributor

While I do appreciate the need for AssemblyReferences for backwards compatibility, I hope we're able to do something that discourages usage moving forward. It's really hard to figure out what flavor of a given assembly to use in a lot of cases [consider multiple RIDs, multiple TFMs] and I'm very nervous that folks will get really frustrated when trying to carry over their already-well-known usage patterns.

@Petermarcu
Copy link
Member

Its not just backwards compatibility. We can't expect that everything is going to be put into a nuget package to be shared. For pure IL .NET Standard libraries, there shouldn't be any RID/TFM concerns. For people that just want to ship a flat folder of assemblies in an sdk, they should be able to tell people to reference them.

eerhardt added a commit to eerhardt/sdk that referenced this issue Feb 15, 2017
Adding <Reference> items to existing assemblies into the .deps.json file so the host knows to read these assemblies at runtime.

Fix dotnet#120
@martincostello
Copy link
Member

martincostello commented Feb 18, 2017

I'm getting this problem, but only when trying to run unit tests in Visual Studio that exercise code paths that render views such as described under Accessing Views in this testing documentation.

@martincostello
Copy link
Member

Turns out the simple fix was to set <PreserveCompilationContext>true</PreserveCompilationContext> in my tests' .csproj file...

@gimlichael
Copy link

Will a fix be ready for your shipment of VS 2017 in early march?!

@eerhardt
Copy link
Member Author

Will a fix be ready for your shipment of VS 2017 in early march?!

Unfortunately, no. The fix will come as part of ".NET Core 2.0", which is after VS 2017 RTMs.

@gimlichael
Copy link

Thank you @eerhardt , for the reply. When you write ".NET Core 2.0", does that mean we are forced to upgrade our projects that are co-compatible with .NET 4.6.1 and .NET Platform Standard 1.4? Because that is a no-go for me :-/

@eerhardt
Copy link
Member Author

does that mean we are forced to upgrade our projects that are co-compatible with .NET 4.6.1 and .NET Platform Standard 1.4?

No, this doesn't mean you will have to upgrade to 2.0. The reason this feature comes as part of ".NET Core 2.0" is because:

  1. It didn't fit time-wise into VS 2017 RTM.
  2. .NET Core 2.0 will allow you to take existing IL assemblies (for example, built for net40 or net45) and run them on .NET Core. Allowing these assemblies to be referenced from disk (and not forcing them into a NuGet package) will allow you to use these assemblies easier. So it fits with the "theme" of .NET Core 2.0 - which is easier migration of code from desktop .NET Framework to .NET Core.

@gimlichael
Copy link

Thank you for the excellent news, @eerhardt. Keep up the good work 👍

@dasMulli
Copy link
Contributor

Nearly everyone I talked to (mostly on slack) who wanted to "just reference an assembly" would run into type-forwarder/facade-hell without having the right packages in the graph to resolve conflicts. So I agree with @piotrpMSFT that the use of assembly references should be discouraged.
My experience has been that there is a lack of knowledge that:

  • nuget.exe can generate and pack a nuspec file for a given dll using nuget.exe spec that.dll.
  • Any folder can be a nuget package source, so having a solution-local folder with .nupkg files inside which is added to a NuGet.Config is enough to reference custom packages.

Maybe it is enough to just document how to make use of that to wrap dlls into local nuget packages that live in the same GIT repository and don't require to set up a nuget server/feed.

eerhardt added a commit to eerhardt/sdk that referenced this issue Feb 27, 2017
Adding <Reference> items to existing assemblies into the .deps.json file so the host knows to read these assemblies at runtime.

Fix dotnet#120
@Metamorphus
Copy link

So, is the problem fixed? I still sometimes get runtime errors like: "System.IO.FileNotFoundException: Could not load file or assembly '...'. The system cannot find the file specified" for the DLLs that I reference directly from the disk.

@eerhardt
Copy link
Member Author

eerhardt commented May 5, 2017

@Metamorphus - yes this problem is fixed. If you are having problems, please open a new issue with your .csproj and which version of the .NET Core SDK you are using (by copying the output of dotnet --info). And any other information you think would help diagnosing the problem.

@eerhardt
Copy link
Member Author

eerhardt commented May 5, 2017

Also, please set COREHOST_TRACE=1, run your app, and attach the output to the bug as well.

@los93sol
Copy link

Please re-open this as dotnet pack does not work

@eerhardt
Copy link
Member Author

dotnet pack issues are tracked in https://github.com/NuGet/Home/.

@rohit21agrawal - is there an existing issue for this scenario? or should @los93sol open a new one in NuGet/Home?

@rohit21agrawal
Copy link
Contributor

what about dotnet pack does not work? could you please elaborate?

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

Successfully merging a pull request may close this issue.