Non-Azure Deployment through VS 2015 RC - c#

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):
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
Go to YourprojectDir\Properties\PublishProfiles
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>
When You press "Publish" in Visual Studio, you should see this new profile on the list.
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).
Validate Connection
Try the preview tab - it most probably wouldn't work, but in case it does - you're done.
Click Publish
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.

Related

ClickOnce not replacing App_Data files during re-install

I noticed a behavior I don't understand happening with my application's ClickOnce deployment: a database file (Main.accdb) that is marked as a data file isn't replaced in C:\Users\username\AppData\Roaming\AppName after re-installing or installing a newer version.
In the Project Properties > Publish > Application Files I have:
File Name App_Data\Main.accdb
Publish Status = Data File
Download Group = (Required)
Hash = Include
In the file properties I have:
Build Action = Content
Copy to Output Directory = Copy always
When I install my WPF application using ClickOnce the first time, the file is found in C:\Users\username\AppData\Roaming\AppName. However, if I uninstall, delete the file in that folder, and re-install it is not replaced. In fact, anything removed from that folder isn't replaced by re-installation.
I tried various options for the Publish Status but the same behavior happens regardless of which options I choose. I'm using WPF with C# in Visual Studio 2017.
Why is this happening and how can I make it so that the file is always there when the application installs (or even better, launches)?
It turns out that the App_Data folder behaves differently and the issue can be resolved by using a folder with any name except App_Data.
I can't find this documented anywhere except for a handful of forum posts of users with similar issues, however, I was able to verify that it all works exactly as expected once I changed the folder name.
All that being said, Microsoft does seem to want developers to use App_Data for databases, so perhaps this is an exception to the norm and may not be the right approach for most projects. In my case, it's a desktop application that needs to deploy a local Access database to the user's computer on install and keep it up to date/replaced during re-install and updates.

Azure Web Deploy publishing old version of MVC sites .dll

I deploy my MVC site via a web publish within VS 2013 to an Azure location. I have published many times without issue from the same machine and IP address, but yesterday it stopped working.
The publish is placing an old version of my projects .dll in the bin folder on the site. This version no longer exists on my machine, it isn't the projects current Git state (and has never been the current Git state) and is not the version in my Release, Debug or Demo compiled folder. I don't know where it's coming from.
So when I publish, I get errors relating to the database changes because the model behind my context has changed since this old version.
So currently when I publish I have to FTP into my site and replace the WebPortal.dll file with the one in my machines bin folder, and the the site works fine.
What could be causing it to revert to this old .dll and where is it coming from? Have I somehow excluded my changes past a certain point from the publish?
Note - My views are publishing absolutely fine, it is just the .dll that should contain the current compilation of Models, Controllers etc., but instead contains an old version missing loads of stuff.
JK
There might be an old version of your dll on the server that is not being overwritten during publish. Have you tried checking "Remove additional files at destination" the the settings section of the Publish dialog. That should remove all the files from your target location except the one you publish.
If you are still having a problem after that try publishing to your local file system so you can see exactly what publish is sending to your server.
Update:
Steps to publish web application to file system.
right click on your project in the solution explorer menu and select Publish.
In the profile section of the Publish Web menu select Custom publish type, click next.
Select file system in the Publish method drop-down. You should see the target location text box where you can specify your folder.
Continue with the rest of the publish steps with you usual settings and click publish.
Double check that your Build (Menu) > Configuration Manager > Build Configuration for Release has the tick next to Build for the WebPortal.DLL. If it isn't set to build then it would use an older version.
I had the same problem. Goodness knows where the old dll is coming from but in the end I up-versioned the library to a higher number and it seemed to cure it. I suspect the GAC or temporary files might be part of the problem although I can't find my library there.

Installing ClickOnce from several URLs

I have a ClickOnce application that needs to be setup from several URLs. For example that I need it to be installed from the following URLs:
http://mycompany.com//url1
http://mycompany.com//url2
I publish it based on installing from url1 (publish wizard -> page two -> from web specify the URL: url1), but when I try to copy it to url2, it still looks at url1.
To do this, I set the installation folder URL to
http://mycompany.com//url1
and checked Exclude deployment provider URL and published the application to a directory on my pc and then I copied it to the server.
How can I force it to use url2 when the installation is started from a index.html on url2?
Edit1
I did several tests to see why what is happening.
The publish wizard creates a HTML file called index.htm.
In this HTML file, there is a button that has a reference to setup.exe. When this application runs, it looks for .application from url1. I checked and there is no reference to url1 in the HTML file, but setup.exe looks at .application from url1.
If I delete all files from url1, but all of them exist on url2, the application setup fails by an error that it can not find http:\mycompany.com\url1\myapplication.application.
If I create a new version of the application and upload it to url1, then go url2 and try to install it, the newer application is installed, but no update happens.
My settings are:
Options:
Deployment
Automatically generate deployment... Set
Open deployment web Set
Use .dep file ex Not set
For CD installation, aut Set
Verify files uploaded to a web sever Not set
Manifests
Block application from Not set
Allow URL parameters to pass Not set
Use application manifest for trust Not set
Exclude deployment provider URL Set
Create desktop shortcut Set
Publish location
publish/
Installation folder URL
http://MyCompany.com/url1
This application is available offline Set
Publish wizard
How the user install the application:
From a web site URL =url1
Yes this application is available online and off line set.
That is really weird - please make sure you indeed deleted everything from both URLs. After you generate ClickOnce deployment files with "Exclude Deployment Provider URL" option, there is no mention of the installation URL in the <<your application name>>.application file - so from my point of view, there are two possible scenarios:
You copied the wrong (old) deployment files into the URL2 folder (or did not override them).
You are doing a manual update from your application with URL1 hardcoded somewhere.
In my case exactly same scenario works as it should work - multiple URLs - multiple installations.

Build (and Debug) ASP.NET Web Application in a non-default folder location

I have a Visual Studio 2008 solution with an ASP.NET Web Application project. I want to change the default output folder, of said project, to $(SolutionDir)\WebApps\$(ProjectName)\bin. This I can do and when I build I get the expected assembly files in this folder. It doesn't copy the content files (aspx, etc.) to the parent folder but I have managed to fix this by hacking the project.csproj file with a custom build target.
The problem is I want to be able to debug this application using the ASP.NET Development Server, by pressing F5 in VS2008. Unfortunately the ASP.NET Dev server starts, has a "Physical Path", in the project directory rather than the parent of the output directory.
Is there any way to build my web application to a different output folder but still run the asp.net dev server to debug my site?
Thanks.
Short answer is yes, but it isn't pretty. The process I used is given below.
Unloaded the project in VS.
Manually edited the .csproj file to include a post build action that basically copies the content files (aspx, etc.) to the parent of the output folder.
For the debug options I set the project to launch an external executable. The Asp.Net Development server. Also manually set the url to launch.
What I learnt? I wouldn't do this, I'd just stick with the default and create an install/web deployment project instead.

Remote-Debugging in Running Web Application

We are trying to add a new page to a running web application. such that a new dll and aspx file are being added. I've setup break points in the code file and Built the application transfering the dll to the remote machine bin file and the aspx page to a folder within the web application. Note this folder is not in the same folder hierarchy as it built in. I'm not sure if thats the problem. Basically we are appending new functionality to a web application.
I've completed the following
I've copied the correct Remote Debug Monitor to the server and have it running.
I'm able to attach to the process which in this case is w3wp.exe (I've Identified that it is the correct process for my application.
I deployed the *.dll to the the bin folder with the *.pdb file along with it.
I've deployed the *.aspx file to the location we want.
With the file open in visual studio with breakpoints setup, we attach to the process and debug. I get 'No symbols loaded' and the breakpoint go empty.
I'm missing something it seems. I've searched the net but have only found complete publish\ deployment scenario.
Any thoughts
Tools -> Options -> Symbols -> Add the path to your deployed web application dlls and pdbs.
You might also need to uncheck "Enable Just My Code" under general debugging.
Here's a more detailed answer that got it working for me in the past: Remote Debugging is not breaking on errors

Categories