Sdk: How do you publish a website with dotnet cli and upload to server?

Created on 30 Mar 2016  Â·  24Comments  Â·  Source: dotnet/sdk

What i mean is that before, when using dnx publish it would create 3 folders, wwwroot, approot and logs. You then uploaded these 3 folders to your server, and pointing the IIS at the wwwroot folder that you just uploaded. Boom website running.

Now it seems to create a folder called publis in the following path MyProject\bin\Debug\net451\win7-x64

Now if i upload the contents of this folder, which consists of 3 folders called refs, Views, wwwroot and lots of dlls to my website, and point IIS at the wwwroot folder i uploaded. IIS doesnt work.

Part of my project.json file is as follows in my website project

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

"commands": {
    "web": "My.Web.App"
},

"content": [
    "wwwroot",
    "Views"
],

"frameworks": {
    "net451": {
        "frameworkAssemblies": {
            "System.ComponentModel": ""
        }
    }
},
question

All 24 comments

@moozzyk this seems to be your territory?

@Gillardo - can you show me your web.config file? If you want to use IIS you need to install AspNetCoreModule and tweak the web.config file accordingly. We do have the publish-iis tool that tweaks the web.config but it needs to be updated to the latest version of dotnet cli.

Here is my web.config file which is in the wwwroot folder of my application

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
        </handlers>
        <httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
    </system.webServer>
</configuration>

No one is setting the %DNX_PATH% variable. You need to replace it with the path to your application. If you have .exe in the published output set /processPath="..{yourApp.exe}". If you are using shared runtime (your app is a .dll) you need to modify the config as followsprocessPath="dotnet" arguments="..{yourApp.dll}"`. You may need to use the full path to dotnet.exe as per https://github.com/aspnet/IISIntegration/issues/109 if you are using shared framework.
As a side note - we are moving away from httpPlatformHandler in favor of AspNetCoreModule. See this post https://github.com/aspnet/Announcements/issues/164 for more details.

sorry i have not tried this yet, bit behind on stuff. i will try this within next couple days

The new publish-iis tool is available. It should create a correct web.config for you. See more details here: https://github.com/aspnet/Announcements/issues/169. (You can even delete the old config you have if you don't have any custom setting - the tool will create a web.config for you after you application is published).

Right guys i am ready to do this, but i am lost, can someone help please? my framework in my projects are like so

"frameworks": {
    "net451": {
        "frameworkAssemblies": {
            "System.ComponentModel": { "type": "build" }
        }
    }
},

Every example doesnt seem to use net451. I have tried keeping this the same and also changing the postpublish command, but it fails everytime

@Gillardo Yes, deploy the entire contents of the publish folder. You will probably want to add a logs folder either to the project itself by adding logs to the publishOptions > include ...

"publishOptions": {
    "include": [ "Views", "wwwroot", "Logs" ]
},

You'll also need to put a dummy text file in the logs folder in your project, as dotnet cli will not copy an empty folder to the publish output. That's a bug that they will fix for RTM.

Your other option for logs is just to manually add a logs folder to IIS physical path folder on the server. As long as the web.config file has the correct stdoutLogFile path for the logs folder, you will get application logs when you enable them.

You can follow the draft guidance for publishing to IIS here: https://github.com/GuardRex/Docs/blob/guardrex/publish-to-iis-rc2-update/aspnet/publishing/iis.rst

[EDIT] ... except for the .NET Core Windows Server Hosting Bundle ... that's not ready yet. You need to install the ASP.NET Core Module from this link: http://download.microsoft.com/download/7/2/D/72DD68D5-7386-4A41-8B8F-E21779A69E33/aspnetcoremodule_x64_en.msi See: https://github.com/aspnet/Announcements/issues/164

Yep installed ASP.NET Core Module already...still nothing. Doesnt create a log or anything, just returns the very stupid, unhelpful

image

@Gillardo It actually should be creating the log with that Detailed Error Information (i.e., I can see the Module there).

If there is no log created, then it's likely that the path provided to stdoutLogFile doesn't exist. Now under these conditions if it has a good path to provide a log file, I expect it will create the file but that the file will be empty. Then, you have to check ...

Does the Application Log say: Process '0' failed to start. Port = PORT, Error Code = '-2147024894'.? If so, then it's likely one of these three things ...

  • Check the processPath attribute on the element in web.config to confirm that it is dotnet for a portable application or .\my_application.exe for a self-contained application.
  • You may have deployed a portable application without installing .NET Core on the server. If you are attempting to deploy a portable application and have not installed .NET Core, run the .NET Core Installer on the server. See Install the .NET Core Windows Server Hosting Bundle.
  • You may have deployed a portable application and installed .NET Core without restarting the server. Restart the server.

[EDIT] ... and note that when I say "Application Log," I mean the Windows OS Application Log (via Event Viewer). That will likely be a point of confusion for all of us going forward that these two logs with a .NET Core app will have the same name.

This is now what my web.config file looks like, which i believe is ok. The stdLogoutFile was set to False, i have now set it to true, but still no logs created.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!-- Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380 -->
  <!-- This repository cannot use the publish-iis tool because there's a bug in the installer if the tool package is a project reference -->
  <!-- See https://github.com/dotnet/cli/issues/1215 -->

  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <!-- This set of attributes are used for launching the sample for full CLR (net451) without Visual Studio tooling -->
    <aspNetCore processPath=".\my.project.name.exe" arguments="" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>

My folder structure is

webRoot
|-- logs
|-- refs
|-- Views
|-- wwwroot <---- IIS is pointing to this as its root folder
| dlls and 1 .exe file which is named the same as my project

My IIS is configured to look at the physical path as the wwwroot folder within my webRoot folder.
Application pool setup, no .NET CLR Version selected.
Installed ASPNET Core.
Restarted server, and ran iisreset multiple times.
I have given Everyone all permissions on the folder an sub folders (just to rule out permission issues)

Well i have nearly got it working.... I have changed the paths in the web.config file to ..\ instead of .\
since the exe file and the logs folder is in the folder above the wwwroot. Not sure if this is a bug or should i have set something before publishing? But now i have updated the paths in the web.config and thought it was working, none of my MVC Views are not being found?

I have to laugh or i will go crasy :)

Dont understand why on my machine (running with dotnet run) my contentroot is C:\Inetpub\Folder, yet publishing and uploading to the server, the contentRoot is C:\Inetpub\Folder\wwwroot

@Gillardo - to make it easier. Move web.config from wwwroot to the folder where your application is and (you would need to reconfigure your IIS accordingly) then change the paths back to be .\ instead of ..\. Once you make it work we may work on moving it back to wwwroot. The issue is that if the web.config is in wwwroot Views are resolved relative to this path and not to the path where you application is and therefore they can't be found.

@moozzyk STAR! I changed my IIS to point to the application, and not the wwwroot folder, then moved the web.config into that same folder and it works. Thanks again!

:+1: If you are interested in the topic of having the physical path point to wwwroot, see the discussion at https://github.com/aspnet/IISIntegration/issues/164

^^^ warrior ... wwwroot ... stupid phone! :smile:

@GuardRex fixed it for ya! 😄

why? warrior was amusing ;)

Lmao...i really asked myself "warrior?"
On 10 May 2016 5:24 p.m., "Pawel Kadluczka" [email protected]
wrote:

why? warrior was amusing ;)

—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
https://github.com/dotnet/cli/issues/2135#issuecomment-218212229

If you run:
dotnet publish ./FolderName the web.config doens't get transformed.

If you run:
dotnet publish ./FolderName/project.json it does..

https://github.com/dotnet/cli/blob/164244f4df32b8fb3e90d5ab1507df985b15aae5/src/dotnet/commands/dotnet-publish/README.md

The doc indicates ...

dotnet publish needs access to the project.json file to work. If it is not specified on invocation via [project], project.json in the current directory will be the default. If no project.json can be found, dotnet publish will throw an error.

^ That's not entirely clear. [project] could be the path to the project, or it could be the path to (and including) the project.json.

Looks like if the filename isn't specified that it doesn't bother to check the path provided. Their example seems to show that it needs the full path ...

dotnet publish ~/projects/app1/project.json

You might want to open a dedicated issue on this. I think you're on to something there ... one would think that the path to the project directory should be enough.

@GuardRex thanks for your reply!

Strange enough I'm not able to reproduce the issue anymore..
I'm quite certain the web.config wasn't updated as expected when only specifying the folder.

Will try some more the upcoming days.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gkhanna79 picture gkhanna79  Â·  3Comments

fmorriso picture fmorriso  Â·  3Comments

aguacongas picture aguacongas  Â·  3Comments

dsplaisted picture dsplaisted  Â·  3Comments

natemcmaster picture natemcmaster  Â·  3Comments