Joe Audette
Joe Audette

Reputation: 36736

Can't seem to get class library projects to build after upgrading aspnet 5 from beta4 to beta5

after upgrading from aspnet beta4 to beta5 I have a solution with multiple class library projects and a single web app. I'm getting all kinds of errors. So I started over creating a new web app project with users/identity/ef. I worked through all the issues upgrading this project to beta5 and it works. Then I added a new class library project to that solution and I get the same kinds of errors as with my other more complex solution.

dnvm list:

   Active Version     Runtime Architecture Location                   Alias
   ------ -------     ------- ------------ --------                   -----
   1.0.0-beta4 clr     x64          C:\Users\Joe\.dnx\runtimes
   1.0.0-beta4 clr     x86          C:\Users\Joe\.dnx\runtimes
   1.0.0-beta4 coreclr x64          C:\Users\Joe\.dnx\runtimes
   1.0.0-beta4 coreclr x86          C:\Users\Joe\.dnx\runtimes
   1.0.0-beta5 clr     x64          C:\Users\Joe\.dnx\runtimes
*    1.0.0-beta5 clr     x86          C:\Users\Joe\.dnx\runtimes default

my solution has this global.json:

{
  "projects": [ "src", "test" ],
   "sdk": {
    "version": "1.0.0-beta5"
}

my class library has this project.json

 {
  "version": "1.0.0-*",
  "description": "",
  "authors": [ "" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "dependencies": {
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta5",
"System.Runtime": "4.0.20-beta-23019"


  },

  "frameworks": {
"dnx451": { },
"dnxcore50": {
  "dependencies": {
    "System.Collections": "4.0.10-beta-3019",
    "System.Linq": "4.0.0-beta-23019",
    "System.Threading": "4.0.10-beta-23019",
    "Microsoft.CSharp": "4.0.0-beta-23019"

    }
  }
 }
 }

I have a single class file in the class library project:

using Microsoft.Framework.Configuration;
using System;

namespace myapp.Configuration
{
public static class ConfigurationExtensions
{

    public static string GetOrDefault(this IConfiguration config, string key, string defaultIfNotFound)
    {
        string result = config.Get(key);

        if (string.IsNullOrEmpty(result)) { return defaultIfNotFound; }

        return result;
    }

    public static int GetOrDefault(this IConfiguration config, string key, int defaultIfNotFound)
    {
        string result = config.Get(key);

        if (string.IsNullOrEmpty(result)) { return defaultIfNotFound; }

        return Convert.ToInt32(result);
    }

    public static bool GetOrDefault(this IConfiguration config, string key, bool defaultIfNotFound)
    {
        string result = config.Get(key);

        if (string.IsNullOrEmpty(result)) { return defaultIfNotFound; }

        return Convert.ToBoolean(result);
    }

    public static Guid GetOrDefault(this IConfiguration config, string key, Guid defaultIfNotFound)
    {
        string result = config.Get(key);

        if (string.IsNullOrEmpty(result)) { return defaultIfNotFound; }
        if (result.Length != 36) { return defaultIfNotFound; }

        return new Guid(result);
    }
}
}

when I try to build I get numerous errors like these:

Error CS0518 Predefined type 'System.Void' is not defined or imported ClassLibrary1.DNX 4.5.1 Error CS0518 Predefined type 'System.Object' is not defined or imported ClassLibrary1.DNX 4.5.1 Error CS0518 Predefined type 'System.String' is not defined or imported ClassLibrary1.DNX 4.5.1 Error CS0433 The type 'Guid' exists in both 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Any ideas how to resolve these errors

UPDATE with this minimal class library by trial and error I found that if I removed the dependency for System.Runtime from the project.json then this simple class library would build.

So to clarify the problem it seems after updating to beta5 from beta4 now any project that has any one of these specific dependencies (and probably others but these for sure) will not build and will get these errors about primitive types.

"System.Runtime": "4.0.20-beta-23019"
"System.ComponentModel.Annotations": "4.0.10-beta-23019"
"System.Xml.XmlDocument": "4.0.0-beta-23019"

unfortunately I do need some of these for my code to work

seems like something is funky in the package dependency chain

so far upgrading to beta5 from beta4 has been a total train wreck for me. I'm hoping maybe someone knows how to resolve these issues but if I get no timely response I guess my next step is to try to go back to beta4 and remove beta5

has anyone else had any luck migrating a multi project solution from beta4 to beta5?

Upvotes: 3

Views: 2718

Answers (1)

Joe Audette
Joe Audette

Reputation: 36736

ok, for my purposes I solved the build problem by dropping the target for dnx451 in each of my projects and then configuring my web app to use the specific DNX version 1.0.0-beta5 .NET Core. that is in project.json for each project I removed "dnx451": { }, from the frameworks section, and in the properties for the web project I specified the DNX version to use.

I suspect there is some kind of packaging snafu that is causing all the dnx451 errors I was having.

For now my assumption is if it works under dnxcore50 then it will work later on dnx451/desktop framework. that is I assume dnxcore50 is a subset of the desktop framework and for now that is all I really need to work with to move forward with my app. I figure I can safely drop support for desktop framework now and add it back later after the packaging snafu has cleared up.

by targeting only dnxcore50 in all of my project.json files I was able to get past all the errors and build and run my solution without errors.

Upvotes: 1

Related Questions