发布 ASP.Net 核心失败并出现 NullReferenceException

Publishing ASP.Net Core Fails with NullReferenceException

我构建了一个相对简单的 ASP.Net 核心 Web 应用程序,它使用 Angular 2 & bootstrap 作为前端,使用 WebApi 作为后端。

我能够在本地构建和 运行 我的应用程序(到 IIS Express),它工作得很好,但是,当我尝试使用 Build -> Publish 菜单时,我遇到了一个 NullReferenceExceptionError可怕的无益。这是我 运行 发布时的输出:

1>------ Publish started: Project: MyProject, Configuration: Release Any CPU ------
Connecting to C:\ProjectDir\MyProject\./bin/Release/PublishTest...
rmdir /S /Q "C:\Users\UserName\AppData\Local\Temp\PublishTemp\MyProject86\"
Environment variables:
Path=%PATH%;.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git
C:\Program Files\dotnet\dotnet.exe publish "C:\ProjectDir\MyProject" --framework net452 --output "C:\Users\UserName\AppData\Local\Temp\PublishTemp\MyProject86" --configuration Release --no-build
Publishing MyProject for .NETFramework,Version=v4.5.2/win7-x64
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(149,5): Error : Object reference not set to an instance of an object.

1>Publish failed due to build errors. Check the error list for more details.
========== Build: 0 succeeded, 0 failed, 3 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

我尝试将文件系统发布到服务器 运行ning IIS 上的目录以及本地目录,并且我在这两个实例中得到相同的输出。

我已经清理了我的解决方案,重建并重新启动了 Visual Studio 以防万一它处于错误状态。我创建了几个不同的发布配置文件,只是为了确保没有配置错误(其中一些也是在 VS2015 重启后创建的)。

此外,在我开始遇到这个问题后,我确保更新了 VS2015,我现在 运行ning 版本 14.0.25425.01 更新 3。我还安装了最新的网络工具。

这是我的 project.json 文件:

{
    "dependencies": {
        "Microsoft.NETCore.App": {
            "version": "1.0.0-rc2-3002702",
            "type": "platform"
        },
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
        "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
        "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final",
        "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final"
    },

    "tools": {
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
            "version": "1.0.0-preview1-final",
            "imports": "portable-net45+win8+dnxcore50"
        }
    },

    "frameworks": {
        "net452": {
            "imports": [
                "dotnet5.6",
                "dnxcore50",
                "portable-net45+win8"
            ],
            "dependencies": {
                "aDependency": {
                    "target": "project"
                }
            }
        }
    },

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

    "runtimeOptions": {
        "gcServer": true
    },

    "publishOptions": {
        "include": [
            "wwwroot",
            "web.config"
        ]
    },

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

我一直在寻找其他遇到此问题的人,我相信我发现了其他一两个似乎遇到过此问题的地方,但我还没有找到任何人回答了解决方案甚至理论到底发生了什么。任何帮助、理论或线索将不胜感激。

感谢您的宝贵时间。

编辑:正如评论中所建议的那样,我创建了一个新的 ASP.NET 核心应用程序,因为 1.0.0 已发布并查看了差异。它起作用了,我觉得错过这个很愚蠢,无论如何,对于 运行 陷入这个(尽管时间有限)问题的任何人,这里是固定的 project.json 文件:

{
    "dependencies": {
        "Microsoft.NETCore.App": {
            "version": "1.0.0",
            "type": "platform"
        },
        "Microsoft.AspNetCore.Diagnostics": "1.0.0",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0",
        "Microsoft.AspNetCore.Mvc": "1.0.0",
        "Microsoft.AspNetCore.StaticFiles": "1.0.0"
    },

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

    "frameworks": {
        "netcoreapp1.0": {
            "imports": [
                "dotnet5.6",
                "dnxcore50",
                "portable-net45+win8"
            ],
            "dependencies": {
                "aDependency": {
                    "target": "project"
                }
            }
        }
    },

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

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

    "publishOptions": {
        "include": [
            "wwwroot",
            "web.config"
        ]
    },

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

我认为您应该将您的应用程序从 RC2 更新到 1.0.0,并且您可能想要使用 1.0.0 和来自 dot.net 的最新 tooling/vs 项目模板创建一个新的网络应用程序,然后进行比较project.json 和启动代码到您现有的应用程序并更新现有的应用程序