Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-Azure Deployment through VS 2015 RC

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. VS 2015 RC Publish Option

However, I'm missing out a very important feature: the ability to publish to a non-Azure server. VS 2015 RC Publish

In earlier versions of Visual Studio (I'm using VS 2013), the Custom options is there.

Custom publish option

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?

like image 430
Nicholas Lie Avatar asked Apr 22 '15 03:04

Nicholas Lie


1 Answers

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):

Preparation

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:

  • one that points to the root application dir and will be used just for deployment. I will name it mysite-deploy.
  • one that will be used to actually host our website and will point to wwwroot dir. I will name it simply mysite.

Deployment

  1. Go to YourprojectDir\Properties\PublishProfiles
  2. Create an empty pubxml file (i.e. 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>
  1. When You press "Publish" in Visual Studio, you should see this new profile on the list.
  2. Fill out the Connection tab, as you would normally do (set Server, Site Name, etc.). Remember to set Site Name to the deployment site (mysite-deploy).
  3. Validate Connection
  4. Try the preview tab - it most probably wouldn't work, but in case it does - you're done.
  5. Click Publish
  6. Check progress in the Web Publish Activity window.

Possible errors

Out of the box, the publish will probably fail. Now it gets tricky :)

ERROR_FAILED_TO_DESERIALIZE

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.

ERROR_CERTIFICATE_VALIDATION_FAILED

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'

ERROR_COULD_NOT_CONNECT_TO_REMOTESVC

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 changeServerfield in Publish profileConnectiontab to:myhost:8172. That's because the powershell script automatically addshttps://and/msdeploy.axd`.

ERROR_PROVIDER_NOT_FOUND

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.

Only the content of wwwroot directory gets deployed

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.

Testing

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.

like image 99
qbik Avatar answered Nov 15 '22 17:11

qbik