Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot publish ASP.NET 5 that references a class library to Azure

Originally I had a working ASP.NET 5 project that could be published to Azure with no problems. I then decided to split the DAL into a separate class project but came across many dependency problems. I then decided to create a blank project with a blank class library to see if I could work out what the problem was but I cannot even publish that either.

Steps:

  1. Create new ASP.NET 5 Web API Preview Template project (also creates solution).
  2. Add class library to the solution.
  3. Change class library target framework to .NET 4.5.1 from 4.6
  4. Reference class library from ASP.NET 5 project.
  5. Attempt to publish.

This is the project structure:

enter image description here

The resulting ASP.NET 5 project.json:

"frameworks": {
    "dnx451": {
        "dependencies": {
            "ClassLibrary1": "1.0.0-*"
        }
    },
    "dnxcore50": { }
},

So it references successfully and I can build and deploy on self hosting but if I try to publish it to Azure, I get the following error message:

The "Dnu" task failed unexpectedly.
System.Exception: 
Microsoft .NET Development Utility CLR-x86-1.0.0-beta6-12256
Copying to output path C:\Users\MyUserDir\AppData\Local\Temp\PublishTemp
Time elapsed 00:00:04.1309210

   at Microsoft.DNX.Tasks.Dnu.Execute()
   at      Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.    <ExecuteInstantiatedTask>d__26.MoveNext()

I am using Visual Studio 2015 and ASP.NET 5 Beta 7.

EDIT: After some playing around, I don't think my answer is quite right. I now realise that there are cases where one can't use the new type of class library e.g. existing older class libraries, which may be impractical to port. Is there some way to do this?

I have tried doing dnu publish and it publishes perfectly fine. I then FTP the output onto the server but then it gives me a Runtime Error. I tried to remotely debug it using Visual Studio. I can see exceptions being thrown when I access the site but I have no way to see what exactly the problem is. One of the first exceptions thrown is:

Exception thrown: 'System.InvalidOperationException' in AspNet.Loader.dll

When I looked in the logs, it gave me Couldn't determine an appropriate version of runtime to run.

like image 968
Kevin Lee Avatar asked Aug 11 '15 08:08

Kevin Lee


1 Answers

It turns out that I was using the incorrect Class Library project. I was apparently using the old Class Library and not the new PREVIEW version, which is also labelled with (Package).

Class Library Project

The description threw me off a bit as it said it was used to create NuGet packages but now everything works fine and the ASP.NET 5 project can be deployed to Azure with successful reference to the Class Library.

like image 189
Kevin Lee Avatar answered Oct 22 '22 10:10

Kevin Lee