3

I have developed a C# Library Framework that targets both .NetStandard & .NetFramework. This was done by editing the .csproj file, changing TargetFramework to TargetFrameworks and adding both of them in the tag:

<TargetFrameworks>netstandard2.0;net471</TargetFrameworks>

I'm now able to add this framework as a ProjectReference in my other projects.

This works great for all projects that have a .csproj file.

However when adding the framework to an asp web site project (That does not have a .csproj file), I get some very strange build errors.

Could not get dependencies for project reference 'XX.Framework' wwwroot    

The type 'System.Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

My TargetFramework for the web site is 4.7.1, as seen in my web.config:

<compilation debug="true" targetFramework="4.7.1">

I see from the file size of the imported .dll, that it is getting the dll for .NetStandard not .NetFramework. Properly why I'm getting build errors.

Note that when adding the framework via nuget, instead of project reference, it does get the correct dll, meaning the .NetFramework dll. And therefor no build errors.

My question is this: Why is asp.net web sites ignoring my targetFramework in web.config, when adding multi target frameworks, by project reference?

Edit 1: My website structure:

enter image description here

Edit 2: VS solution with an example of the problem. https://github.com/srenrd/MultiFrameworkExample

user2408952
  • 2,011
  • 5
  • 24
  • 26
  • I'm having a hard time believing that asp web sites don't have a .csproj file, can you show us your source for this? – MindSwipe Mar 27 '19 at 09:41
  • It's a very old school web site. See edit 1, for the entire project structure. – user2408952 Mar 27 '19 at 10:15
  • It might be more helpful if you post a screenshot of the Solution Explorer within Visual Studio – MindSwipe Mar 27 '19 at 10:17
  • Thx, I've replaced the screenshot. – user2408952 Mar 27 '19 at 10:27
  • Weird, wwwroot isn't supposed to be root of your project, how did you create it? Some more info on [this](https://stackoverflow.com/a/27648100/9363973) Stack Overflow answer – MindSwipe Mar 27 '19 at 11:14
  • Again this is a very very very very old school web site. There's nothing wrong with the project structure itself. – user2408952 Mar 27 '19 at 11:36
  • you didn't say if you get the error at package install, package restore or build. – zivkan Mar 27 '19 at 19:51
  • from a quick test, you should also check your `.sln` file, because mine lists the TargetFrameworkMoniker. Make sure it matches the TFM listed in your web.config file. – zivkan Mar 27 '19 at 20:40
  • @zivkan it is a build error. TFM is 4.7.1, so i dies match the web.config. – user2408952 Mar 27 '19 at 23:24
  • @user2408952, hi, what's your VS version and if you create a new asp.net website project to test, if this issue persists, could you please share the detail steps to reproduce this issue or share a sample solution, that will help us analysis, thanks in advance. – Sara Liu - MSFT Mar 28 '19 at 06:31
  • @SaraLiu-MSFT See edit 2 for an example. – user2408952 Mar 28 '19 at 12:19

1 Answers1

0

Per the sample code, please add the following code into the Web.config file:

<assemblies>
    <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
  </assemblies>

enter image description here

Sara Liu - MSFT
  • 6,007
  • 1
  • 21
  • 27
  • 1
    This does remove the "is defined in an assembly that is not referenced" error. And yes i does make the site build. However it still retains the error "Could not get dependencies for project reference". – user2408952 Mar 29 '19 at 08:51
  • Please have a try with my test solution that comes from your shared code: https://1drv.ms/u/s!Atv5QNuFrncKmFXJgjfVX6CuB_iQ, btw, what's your VS version? – Sara Liu - MSFT Mar 29 '19 at 09:27
  • Tried your solution, same result. Try rebuilding your solution and you should see the error in your Error List (Even if it says "Rebuild All: 2 succeeded, 0 failed, 0 skipped" in the Output). Using VS 2017 and 2019 (Preview). – user2408952 Mar 29 '19 at 10:41
  • Thanks for your detail information, I can got the same result as yours, please go to Help-Send Feedback-Report a problem to report this issue to the VS Product Team, if you want me to help you, please feel free to let me know :) – Sara Liu - MSFT Apr 01 '19 at 09:50
  • I've send a bug report to the VS Product Team. Thx for the help. – user2408952 Apr 02 '19 at 08:08
  • @user2408952 Any update on this? I'm trying to reference SDK-style projects in a ASP.NET Web Site Project (WSP) (so *not* a Web Application Project / WAP). I'm wondering whether you managed to get rid of the build error. – Steven Volckaert Jan 13 '20 at 12:29
  • @user2408952 Yes, any update on this? Cant seem to remove those errors even though the project builds fine etc. – mRf Sep 16 '20 at 12:38
  • 1
    Well for anyone with the same issue, MS is not going to fix the problem. https://developercommunity2.visualstudio.com/t/Problem-with-multi-target-frameworks-in/512022?space=8&q=web+site+project+TargetFrameworks – goroth Aug 05 '21 at 18:51