9

In my ASP.NET 5 RC1 project (targeting only dnx46) I'm trying to add a reference to a (classic) Class Library project targeting .net 4.6.

I get this error at build time: ...\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3274: The primary reference "...\ClassLibrary1.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5.1".

Why is this happening? My ASP.NET 5 project isn't targeting 4.5.1. According to the project.json file it's only targeting dnx46. I can't find any mention of .net 4.5.1 anywhere.

Here's the project.json for my WebApplication project:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx46": {
      "dependencies": {
        "ClassLibrary1": "1.0.0-*"
      }
    },
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

And here's the project.json that the "wrapping" process creates for my ClassLibrary project:

{
  "version": "1.0.0-*",
  "frameworks": {
    "net46": {
      "wrappedProject": "../../ClassLibrary1/ClassLibrary1.csproj",
      "bin": {
        "assembly": "../../ClassLibrary1/obj/{configuration}/ClassLibrary1.dll",
        "pdb": "../../ClassLibrary1/obj/{configuration}/ClassLibrary1.pdb"
      }
    }
  }
}
3
  • 1
    Can you share the project.json files of the two projects? Nov 22, 2015 at 19:31
  • Sure, I updated the question to include the project.json files. Nov 22, 2015 at 21:52
  • 2
    I have the same warning, 4 months later.. but it doesn't seem to be wrong otherwise, it works.
    – rfcdejong
    Feb 17, 2016 at 11:52

3 Answers 3

2

The warning is still there if built using VS 2015 Update 1, but web app works well and can call a method from .net4.6 assembly.

1

try to upgrade your utilities and Runtime version if you have't upgraded it yet.

  • dnvm upgrade

then from the shell point to your working\project folder clean the cache and restore the project packages

  • dnu clear-http-cache
  • dnu restore

then try build it

  • dnu build
1
  • I think it has nothing to do with dnu, it seems is a MSBuild issue, in RC1 I still have the same issue. Anyway I tried your comment and it's still showing the same warning.
    – rfcdejong
    Feb 17, 2016 at 11:51
0

It might be that you're experiencing VS 2015. Setting right target framework for ASP.NET 5 web project. The problem was related to IIS targeting 4.5.1 despite the project targeting the 4.6 framework.

Is your problem happening when you build from Visual Studio or when you run IIS?

The following is working for us.

ClassLibraryNet46

This is a classic .NET Framework class library that has .NET 4.6 as its target framework. There is a one class.

BowserKingKoopa.cs

namespace ClassLibraryNet46
{
    public class BowserKingKoopa
    {
        public static string GetMessage()
        {
            return "Hello to BowserKingKoopa from ClassLibraryNet46!";
        }
    }
}

WebApplicationNetCore

This is an ASP.NET Core Web Application that has only a Startup.cs class. We used Visual Studio to add the reference to the Net46 project (right click, add reference...)

Startup.cs

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;

namespace WebApplicationNetCore
{
    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            app.UseIISPlatformHandler();

            app.Run(async (context) =>
            {
                var message = 
                    ClassLibraryNet46.BowserKingKoopa.GetMessage();

                await context.Response.WriteAsync(message);
            });
        }

        public static void Main(string[] args) => 
            WebApplication.Run<Startup>(args);
    }
}

project.json

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx46": {
      "dependencies": {
        "ClassLibraryNet46": "1.0.0-*"
      }
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.