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

Build error when referencing .NET Framework 4.5 class libraries #127

Closed
Daniel15 opened this issue Aug 2, 2015 · 6 comments
Closed

Build error when referencing .NET Framework 4.5 class libraries #127

Daniel15 opened this issue Aug 2, 2015 · 6 comments

Comments

@Daniel15
Copy link

Daniel15 commented Aug 2, 2015

Repro:

  1. Create a new ASP.NET 5 project using the empty template
  2. Modify project.json so it only targets .NET 4.5.1 (dnx451 in frameworks section)
  3. Add a new class library targeting .NET Framework 4.5 to the solution
  4. Add a reference to the class library in the website (through Visual Studio Add References UI)
  5. Modify the website's Startup.cs to use a class from the class library (eg. var foo = new ClassLibrary1.Class1();)
  6. Attempt to build the solution

This results in error CS0246 ("The type or namespace name 'ClassLibrary1' could not be found (are you missing a using directive or an assembly reference?)") in Visual Studio. However, this just appears to be a design-time issue, as the site does actually execute properly and there are no errors in the "Output" tab.

Note: This appears to be specific to .NET Framework 4.5. Switching the class library to use .NET Framework 4.0 makes it work as expected (no build errors)

Update: Okay I think I figured this out. My repro steps weren't 100% correct and I actually missed a step when I wrote them out. The issue is that when you change the target framework version for an assembly (such as a Class Library), its corresponding project.json in the wrap directory is not updated (eg. to change net40 to net45). I encountered this since I changed a library from .NET Framework 4.0 to .NET Framework 4.5.

Workaround: Manually update the project.json files, or delete the wrap directory and re-add the reference in Visual Studio.

@sayedihashimi
Copy link
Contributor

@BillHiebert thoughts?

@Daniel15
Copy link
Author

Daniel15 commented Aug 2, 2015

Did some more testing, and it looks like using .NET Framework 4.6 in both the site and the class library appears to work, as does using .NET Framework 4.0 in the class library combined with .NET Framework 4.5 in the website. It just seems to be an issue when using .NET Framework 4.5 in the class library.

Another related bug while I was testing this: Selecting ".NET Framework 4.6" in the "New Project" dialog in VS2015 still sets dnx451 in project.json, I needed to manually change it to dnx46

Edit: Now I'm not so sure - Using .NET Framework 4.6 both worked in my small test project, but didn't work in my real larger site, I'm still seeing a lot of compilation "errors" in VS that aren't really errors:

screen shot 2015-08-01 at 7 20 34 pm

(notice it says "Build Succeeded" at the bottom. The site does work properly if I run it)

@Daniel15
Copy link
Author

Daniel15 commented Aug 2, 2015

Okay I think I figured this out. My repro steps weren't 100% correct and I actually missed a step when I wrote them out. The issue is that when you change the target framework version for an assembly (such as a Class Library), its corresponding project.json in the wrap directory is not updated (eg. to change net40 to net45). I encountered this since I changed a library from .NET Framework 4.0 to .NET Framework 4.5.

Workaround: Manually update the project.json files, or delete the wrap directory and re-add the reference in Visual Studio.

@sayedihashimi
Copy link
Contributor

TFS:149636
I've added this to our internal TFS, we will reply back here soon.

@webtools-bot
Copy link

The GitHub Issue Tracker for the aspnet/Tooling repo is being deprecated in favor of Visual Studio's Report a Problem tool.

If this issue is still a problem with the RTW release of Visual Studio 2017, please report a new issue using the Report a Problem tool. While you can still use .NET Core and ASP.NET Preview tools with Visual Studio 2015, Visual Studio 2017 is now the officially supported tool for developing .NET Core and ASP.NET Core projects.

By using the Report a Problem tool (available in both VS 2017 and VS 2015), you can collect detailed information about the problem, and send it to Microsoft with just a few button clicks. See Visual Studio's Talk to Us page for more details.

Please use the discussion topic here for feedback and questions on the deprecation of this issue tracker. Thanks!

@Daniel15
Copy link
Author

Daniel15 commented Apr 3, 2017

This works fine in VS2017 with the latest tooling

@Daniel15 Daniel15 closed this as completed Apr 3, 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

3 participants