0

升级到后netcoreapp1.0我无法运行我的项目。我已经解决了更新、恢复包的所有错误和修复,并且在任何地方都没有错误。

(我按照本指南升级https://docs.microsoft.com/en-us/dotnet/articles/core/migrating-from-dnx

我得到的只是经典Object reference not set to an instance of an object.,让我发疯。

运行命令

$ dotnet run
Object reference not set to an instance of an object.

我的工具:

$ dotnet --info

.NET Command Line Tools (1.0.0-preview2-003121)

Product Information:
 Version:            1.0.0-preview2-003121
 Commit SHA-1 hash:  1e9d529bc5

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.10
 OS Platform: Darwin
 RID:         osx.10.10-x64

(也在我的 Win 10 机器上运行,结果相同,也无法从 cmd 或 Visual Studio 运行)

--log 4也不输出任何东西。

关于如何确定它的任何想法?

更新:

project.json

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "System.Diagnostics.Process" : "4.1.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },

  "tooling": {
    "defaultNamespace": "Avantime.Sniff"
  }
}
4

1 回答 1

0

不确定是什么导致了上述错误,但在阅读了 github 上的各种发行说明和小修复之后,这是使其正常工作所需的调整。

此外,根据代码中比 netcore50 (主要将 EF7 更新为 EntityFrameworkCore)的旧代码,还有大量工作删除了对旧库的所有引用。

我的修复:

添加Program.cs为应用程序的新入口点

public static class Program
    {
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();

        }
    }

Startup根据此修复签名: https ://github.com/aspnet/Announcements/issues/171

        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("config.json");

            [...]

将 package.json 更改为

{
  "dependencies": {
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Mvc.Core": "1.0.0",
    "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.Session": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.NETCore.Runtime.CoreCLR": "1.0.2", <-- IMPORTANT
    "Microsoft.Extensions.PlatformAbstractions": "1.0.0" <-- IMPORTANT
  },

  "buildOptions": {
    "compile": {
      "include": [
        "../../shared/**/*.cs"
      ]
    },
    "copyToOutput": {
      "include": [
        "Areas",
        "Views",
        "wwwroot",
        "config.json",
        "web.config"
      ]
    },
    "define": [
      "DEMO",
      "TESTING"
    ],
    "emitEntryPoint": true, <- IMPORTANT
    "preserveCompilationContext": true,
    "warningsAsErrors": false
  },
  "publishOptions": {
    "include": [
      "Areas",
      "Views",
      "wwwroot",
      "config.json",
      "web.config"
    ]
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },
  "frameworks": {
    "netcoreapp1.0": {
      "Microsoft.NETCore.App": {
        "version": "1.0.0-*",
        "type": "platform"
      },
      "imports": [ "netcore50", "portable-net452+win81" ] <- IMPORTANT
    }

  },
  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-*"
  },
  "scripts": {
    "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
  },
  "webroot": "wwwroot",
  "version": "1.0.0-*",
  "runtimes": {
    "win10-x64": {}
  }
}
于 2016-07-15T09:22:11.027 回答