Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Publish Individual Files to your Server in Visual Studio 2012.2


:P
On this page:

In Visual Studio 2012 Update 2 there's a sweet little new gem, that I championed for some time in the past, and that has finally made it into the VS box: You can now publish individual files to the server without having to publish the entire site. You can now publish 1 or more files simply by selecting them in the Solution Explorer and using the Context Menu's Publish Selected Files or Publish File xxxx.xxx.

PublishIndividualFile

In the past if you wanted to publish your site, it was an all or nothing affair: You basically had to rebuild and re-publish the entire site. Publishing works great when you're making major updates that affect binaries and configuration settings. In that case you do want a full publish to push up your binary file changes as well as web.config transformations etc. This is a great feature and the cornerstone of publishing which is as it should be.

But on more than a few occasions I've:

  • Forgotten to include some content file like an image in a full publish
  • Had to make a really minor change to a content file or image and need to push it up
  • Make some quick iterative changes repeatedly to a file to tweak the UI or an image on the server

Now, with Update 2 you have another option to publishing the entire site -you can now publish an individual file.

I know this is a minor thing, but I can't tell you how often I use this for quick image or CSS updates. Sometimes I actually prefer making changes to these sorts of things on a live site rather than firing up the local copy first especially if the live site is running with a full set of data. It's often convenient to just push individual files. This is especially true for my personal content sites, more so than typical business applications.

 

Web Deploy Getting Easier

As a side note I've been a big fan of Web Deployment in Visual Studio - it's such a tremendous time saver over manually uploading files to the server and trying to figure out what needs updating. Prior to Web Deploy features in Visual Studio I actually had used a custom solution I cobbled together using FTP that provided much of the same functinality including the abililty to push individual files which I found very useful.

It's also great in a team environment, since publish settings are typically shared in source control. This ensures that everybody is pushing up code consistently to the staging or live server using the same settings that are configured only once. It's great when a new developer comes on board especially - they don't have to configure anything they are just ready to go.

When Web Publishing was introduced the intial versions were horrible to the point of unusability. In VS 2010 it improved somewhat, but the server side installation of Web Deploy was still a major pain in the ass. Getting Web Deploy configured properly on the server has been a real pain in the ass with 3 different installs required and several manual configuration steps.

With the latest Web Deploy 3.0 release though, Microsoft finally seems to have gotten Web Deploy right to where it's a single simple installation on the server that just works once installed. There no longer are any finicky configuration settings and it just works off the single install. Inside of the Visual Studio 2012 Web Publish client also has made the Publish Settings dialog a bit more user friendly and more flexible in what you can use to connect to the server. VS now understands pure site urls and virtuals as opposed to the base site url and Site ID/Name that was required previously and was always confusing.

WebPublishSettingsDialog

The end effect is I no longer dread setting up Web Deploy for the first time on a server, nor do I have to go look up the configuration for another site to figure out what put in the boxes :-).

It's kind of sad that it took so long for Web Deploy to get it all right, but now the whole thing is ridiculously smooth. There are a still a few issues with web.config transforms that are difficult to deal with from time to time, but that's not really Web Deploy's problem, but a problem of how to partition developer specific settings in configuration files which is always a problem.

In any case, I hope some of you find the new single file or selected file publishing feature as useful as I have. It's just one more little tweak that makes life easier and shaves a few minutes off the development process. Score!

Posted in ASP.NET  Visual Studio  

The Voices of Reason


 

Bryan
May 10, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

I just wish more hosting companies supported Web Deploy. Since it's an extra installation instead of something that can just be turned on by checking a check box in a site's IIS configuration (or a web.config option) many of the smaller, more economical hosts do not support it.

Rick Strahl
May 10, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

@Bryan - I hear you, but I suppose you can always ask to get it installed - that's worked for me in the past. With Web Deploy 3.0 the install is painless and easy for a server now, which I think was a problem previously.

In fact I remember about 2 years ago I was working on a project where we needed to install Web Deploy and it simply didn't seem to work. It was pretty embarrassing :-) We ended up using the FTP deploy which worked but is quite a bit slower. Same location though was able to install Web Deploy 3 last year no issues, so there are definite improvements there.

FWIW, you can still use the publishing features with FTP for those hosts that don't support Web Deploy. It works great too, although in my experience it is a bit slower than Web Deploy.

David
May 10, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

Hm, for some reason this option is not showing up for me.

I'm on VS2012.2, and I'm using a website (not a web project). I have set up the publish option on the actual site, and that seems to be ok. However, if I right click any files in the web site, I don't get the option to upload.

Any clue if this is restricted to just web projects?

Michael Lang
May 13, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

David,

I have an MVC4 project that it works on, and a Web API project that it does not work on. I have not setup a publish profile for the Web API project yet, but the MVC4 application does publish to Azure. So I presume the menu option requires knowing how to deploy to the target server, which must have Web Deploy 3.0.

Can you setup your Web site project to deploy to Azure, then verify if the menu option works or not. Azure does support Web Deploy 3.0, as that is what I use for my MVC4 web application.

Rick Strahl
May 13, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

@David - This all makes sense. I believe you have to have your publish settings configured before you see the individual options since those options do not prompt for profile or settings - they use the current publish profile. So that would explain why you don't see it for the WebAPI project - yet.

The target server does NOT have to have Web Deploy installed to work. You can also use FTP and direct file tranfer (via UNC or network share).

Steven Carnes
May 14, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

I am on a MVC4 Application, with File System deployment set up and I still do not have the option. Any clue why?

Rick Strahl
May 14, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

@Steven - does a full Publish operation work?

David
May 15, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

Thanks for the responses.

I setup the deploy profile first, but still didn't see the new option.

After poking around a bit more I found this line in the changelog for the update:

"Selective publish – for one or more files you can perform the following actions (after publishing to a Web Deploy endpoint)"

Source - http://www.asp.net/vnext/overview/latest/aspnet-and-web-tools-20122-release-notes-rtw#_Web_Publishing

This makes it sound like it perhaps won't work with an FTP endpoint (which is what I'm using)? Rick, you said it should work with FTP/File transfer though? Have you had this work on your end of things?

Pawel
May 24, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

Is that is supposed to work with VS 2012 For Web? I've installed update but unfortunately there are any changes (I deploy via FTP)

Rick Strahl
May 27, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

I've confirmed that the individual publish features work for Web Site projects even without doing an initial publish. I simply opened a folder site, configured publish and exited out the publish dialog and saved. Then simply right click and Publish individual file without a problem. Sweet!

drzaus
June 14, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

So like comment (http://www.west-wind.com/weblog/posts/2013/May/10/Publish-Individual-Files-to-your-Server-in-Visual-Studio-20122#129723) I can confirm that it does not work for FTP publishing; however if I create both an FTP and a Web Deploy publish profile I do get the menu options for "publish selected file" as soon as I create (save, not execute, as @Rick said) the Web Deploy profile. The context-menu options remain after switching, but the actual publish operation hangs at 0%. I can successfully publish the entire site using the FTP profile.

Justin
July 08, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

I'm using FTP to upload a PHP site. I had been using the VS.PHP plugin which gave a deploy option for selected files in the Solution explorer, but it has other issues. I am now trying out the PHPTools plugin and it allows me to publish the entire site only. Unfortuantely, as you pointed out here, there are times when I need to make a minor change in the middle of a large change. I do not want to publish the entire site at these times, but I's also rather not open an external FTP program to only copy the files I want to update.

I can use the Open Files Filter so I know which of the changed files I want to upload, but then having to go and find them in another program and make sure that I got them all introduces a lot of ebcak risk.

Is there any way to deploy single files over FTP within VS2012?

Rick Strahl
July 08, 2013

# re: Publish Individual Files to your Server in Visual Studio 2012.2

@Justin - no unfortunately for now Individual File Publish is limited to WebDeploy...

Rob Gaudet
August 29, 2014

# re: Publish Individual Files to your Server in Visual Studio 2012.2

Wow, yes, individual file publish is an awesome feature. As is the ability to publish the project from VS. MS please keep making mundane tasks easier on developers!

Costin
March 13, 2015

# re: Publish Individual Files to your Server in Visual Studio 2012.2

It seems that extra settings in the publishing profile are not taken into account on individual publishing.

In my publishing profile I have added some custom settings to minify CSS and JS files. When I publish the entire project, everything works as expected, but if I want to publish just the Scripts folder, the JS files don't get minified anymore.

Also, I have set up the profile to precompile source files, so almost everything ends up in the bin folder. However, there's no way to publish only this folder.

Alex
August 02, 2021

# re: Publish Individual Files to your Server in Visual Studio 2012.2

Hi there,

I can't see the Publish Selected Files optin in the context menu anymore in VS2019. Looking for a solution I do not see anything but answers from MS stating that it's fixed, but actually it's not. Even by pressing the shortcut keys Alt+`, Alt+P, it states "publishing selected files is not available".

Anyone knows how to get it back?

Thanks...Alex.


Rick Strahl
August 02, 2021

# re: Publish Individual Files to your Server in Visual Studio 2012.2

@Alex - it's still there. The default key to publish the current editor file or file(s) selected in the Solution explorer is `alt-p-;' - I use it all the time.

Although that might also depend on the type of project that you're in, but it works for (old) Web Projects, Web Deploy Projects and ASP.NET Core Web Projects.

+++ Rick ---


Jacob
October 04, 2021

# re: Publish Individual Files to your Server in Visual Studio 2012.2

If you have multiple publish profiles which one does it use??


Rick Strahl
October 04, 2021

# re: Publish Individual Files to your Server in Visual Studio 2012.2

@Jacob - in Visual Studio you have to pick the profile that is active. If you publish by command line you need to specify the profile explicitly if you have more than one.


robert
April 22, 2022

# re: Publish Individual Files to your Server in Visual Studio 2012.2

Hi, thank you for your article, I've been using "Publish" for years but I never understood how to select a specific server or publishing profile in general. When you click on Publish I don't have choices, it will publish the file right away using the current profile. This is a major draw-back as I need to publish the whole project anyway the very first time in order to be able to select the profile/server I want to work with, after that I can use Publish single file. Thank you.


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024