Publish Individual Files to your Server in Visual Studio 2012.2
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.
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.
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!
Other Posts you might also like
The Voices of Reason
# re: Publish Individual Files to your Server in Visual Studio 2012.2
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.
# re: Publish Individual Files to your Server in Visual Studio 2012.2
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?
# re: Publish Individual Files to your Server in Visual Studio 2012.2
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.
# re: Publish Individual Files to your Server in Visual Studio 2012.2
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).
# re: Publish Individual Files to your Server in Visual Studio 2012.2
# re: Publish Individual Files to your Server in Visual Studio 2012.2
# re: Publish Individual Files to your Server in Visual Studio 2012.2
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?
# re: Publish Individual Files to your Server in Visual Studio 2012.2
# re: Publish Individual Files to your Server in Visual Studio 2012.2
# re: Publish Individual Files to your Server in Visual Studio 2012.2
# re: Publish Individual Files to your Server in Visual Studio 2012.2
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?
# re: Publish Individual Files to your Server in Visual Studio 2012.2
# re: Publish Individual Files to your Server in Visual Studio 2012.2
# re: Publish Individual Files to your Server in Visual Studio 2012.2
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.
# 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.
# 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 ---
# re: Publish Individual Files to your Server in Visual Studio 2012.2
If you have multiple publish profiles which one does it use??
# 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.
# 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.
# re: Publish Individual Files to your Server in Visual Studio 2012.2