I'm trying out ASP.NET 5 and all its new features on VS 2015 Enterprise RC. To ensure smooth end-to-end deployment, I then try to deploy the application to a non-Azure private server through VS Publish feature.
However, I'm missing out a very important feature: the ability to publish to a non-Azure server.
In earlier versions of Visual Studio (I'm using VS 2013), the Custom options is there.
I've tried tinkering with the Project Properties but nothing on how to deploy my ASP.NET 5 app to a custom server. Any ideas?
It's doable (after all, publishing to Azure websites also uses WebDeploy internally), but it's kinda tricky right now and requires you to tweak a few things. Here's what you can do (for VS 2015 CTP6):
Asp.net vnext has slightly different directory structure than a regular Asp.net app. The are two main directories: approot
and wwwroot
(if you deploy the application to local filesystem, you can browse through them). We want to deploy both those dirs, but the IIS website path has to point to wwwroot
dir. This problem seems to be addressed in Web Deploy 3.6, but i will just deal with it manually. In order for this to work, you can create two websites/applications in IIS:
mysite-deploy
.wwwroot
dir. I will name it simply mysite
.YourprojectDir\Properties\PublishProfiles
mysite.pubxml
) Paste the following content into your pubxml:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
</PropertyGroup>
</Project>
mysite-deploy
).Web Publish Activity
window.Out of the box, the publish will probably fail. Now it gets tricky :)
At first, what I've got is this error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.AspNet.Publishing.targets(205,5): Error ERROR_FAILED_TO_DESERIALIZE: Web deployment task failed. ()
Publish failed to deploy.
Let's try to fix that.
Open the Publish
window again, and check Publish using Powershell script
option on the Settings
tab.
Try again.
If you get an error: ERROR_CERTIFICATE_VALIDATION_FAILED
, this means that the SSL certificate that IIS Management Service
on your target machine is not trusted by your computer. You can try to download the certificate add it to trusted cert store, or you can disable certificate validation altogether.
In the latter case, you need to edit publish-module.psm1
located at C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\1.0.0-pre\publish-module.psm1
. Find the fragment:
# add excludes
$sharedArgs.ExtraArgs += (GetInternal-ExcludeFilesArg -publishProperties $publishProperties)
# add replacements
$sharedArgs.ExtraArgs += (GetInternal-ReplacementsMSDeployArgs -publishProperties $publishProperties)
And add this:
$sharedArgs.ExtraArgs += '-allowUntrusted'
Inspect the exact commandline that is getting invoked - in Web Publish Activity Window
there should be a line logged, starting with Calling msdeploy with the command:
. Look for ComputerName=
. If it looks like this: ComputerName='https://https://myhost:8172/msdeploy.axd'
/msdeploy.axd', then you should change
Serverfield in Publish profile
Connectiontab to:
myhost:8172. That's because the powershell script automatically adds
https://and
/msdeploy.axd`.
More Information: The provider 'contentPathLib' could not be found. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_PROVIDER_NOT_FOUND.
Go again to C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\1.0.0-pre\publish-module.psm1
and find the line:
$publishArgs += '-enableLink:contentLibExtension'
This seems to be a feature of Web Deploy 3.6, but it seems that the server side has to support it also. To disable it, just comment out this line. Warning: This change may impact powershell deployment to Azure websites.
Now that your site is being deployed, there is one more thing. We wanted to deploy approot
and wwwroot
directory, and instead only the content of the wwwroot
directory is deployed. To fix that, we need to once again edit C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\1.0.0-pre\publish-module.psm1
.
Find the line that says:
$webrootOutputFolder = (get-item (Join-Path $packOutput $webroot)).FullName
And after that, add a new line:
$webrootOutputFolder = $webrootOutputFolder | split-path -parent
This will set the published folder to the parent of wwwroot
, which is exactly what we need. Before publishing again, you may want to clear your site's directory on the server - the published directory structure will be different now.
At this point, the site should be deployed and available on the server. On the server side, you should see two directories: approot
and wwwroot
and maybe some script files.
Any server side errors you will have to debug yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With