【问题标题】:Publishing ASP.Net Core Fails with NullReferenceException发布 ASP.Net Core 失败并出现 NullReferenceException
【发布时间】:2016-12-29 07:47:58
【问题描述】:

我构建了一个相对简单的 ASP.Net Core Web 应用程序,前端使用 Angular 2 和引导程序,后端使用 WebApi。

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

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 ==========

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

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

此外,在我开始遇到此问题后,我确保更新 VS2015,我现在正在运行版本 14.0.25425.01 Update 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%" ]
    }
}

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

感谢您的宝贵时间。

编辑:正如 cmets 中所建议的,自 1.0.0 发布以来,我创建了一个新的 ASP.NET Core 应用程序并查看了差异。它奏效了,无论如何,对于遇到这个(尽管时间有限)问题的任何其他人,我都觉得错过这个很愚蠢,这里是固定的 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 的最新工具/vs 项目模板创建一个新的 Web 应用程序,然后比较project.json 和启动代码到您现有的应用程序并更新现有应用程序
  • 这最终成为了答案。我将使用固定的 project.json 文件更新我的帖子。
  • 如果您想将其标记为答案,我已将我的评论作为答案重新发布,我将不胜感激

标签: asp.net iis visual-studio-2015 asp.net-core publish


【解决方案1】:

我认为您应该将您的应用程序从 RC2 更新到 1.0.0,并且您可能希望使用 1.0.0 和 dot.net 的最新工具/vs 项目模板创建一个新的 Web 应用程序,然后比较 project.json 和启动代码到您现有的应用程序并更新现有应用程序

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多