I have built a relatively simple ASP.Net Core web application that uses Angular 2 & bootstrap for the front end and WebApi as the back end.
I am able to build and run my application locally (to IIS Express) and it works just fine, however, when I attempt to use the Build -> Publish
menu I encounter a NullReferenceExceptionError that is terrible unhelpful. Here is the output when I run 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 ==========
I have attempted to do a FileSystem publish to both a directory on a server running IIS as well as just a local directory, and I get the same output in both of these instances.
I have cleaned my solution, rebuilt, and restarted Visual Studio just in case it had been in a bad state. I've created a few different publish profiles just to make certain that something wasn't misconfigured with that (some of them were created after the restart of VS2015, as well).
In addition I made sure to update VS2015 after I started having this problem, and I am now running version 14.0.25425.01 Update 3. I also have the latest web tools installed.
Here is my project.json file:
{
"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%" ]
}
}
I've been searching for anyone else having this issue and I believe I found one or two other places where this seems to have been encountered but I haven't found anyone that has replied with a solution or even a theory to what is happening exactly. Any help, theories, or leads would be appreciated.
Thanks for your time.
EDIT: As suggested in the comments I created a new ASP.NET Core application since 1.0.0 was released and took a look at the differences. It worked and I feel silly for missing this, anyway, for anyone else who runs into this (albeit temporally limited) issue, here's the fixed project.json file:
{
"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%" ]
}
}
I think you should update your app from RC2 to 1.0.0 and you may want to create a new web app with 1.0.0 and the latest tooling/vs project templates from dot.net then compare the project.json and startup code to your existing app and update the existing app