JBeckton
JBeckton

Reputation: 7111

Visual Studio 2010 - How to publish to local IIS during build

I am working on an ASP.Net MVC web app in VS 2010. I want to run the web app in my local IIS 7 under it's own web. I have my hosts file set up so that *.dev points back to my local ip so when I create an IIS web i can just give it a unique host name like myapp.dev and it runs.

This is my first web application project with VS and I am trying to figure out how to make VS publish the web app code to my local web when I hit build. I already have the publish part working but i want to automate it. Also I might add that I have a couple different layers (class libraries) that need to also build and publish all at once.

In summary what I want to happen is after making code changes I want to click rebuild solution or rebuild project and after successful build I want the files that changed to be published to the web root I have set up for this particular web app in my local IIS. Then I can just refresh the browser to test my changes.

Are there any tutorials on this type of set up someone can refer me to?

Upvotes: 6

Views: 27413

Answers (4)

Tim
Tim

Reputation: 1

Being new to ASP.NET, I'll suggest that you look at Url.Content for publishing links (if you are using MVC) or System.Web.VirtualPathUtility.ToAbsolute("~/...") (if not) and make judicious use of the tilde to avoid dealing with the side effects of publishing a site with different roots. Learning this will open up the opportunity to use some of the suggestions above (pointing IIS to your project directory for one).

The other option is open your project file and work with the AfterBuild build target. Uncommenting it and adding an aspnetcompiler task along with a publish task will also accomplish the same thing and if you're doing one-click publish you can also separate your build tasks based on $(Configuration) by specifying a condition.

I'll suggest also that you read up on how to customize builds for web projects. There are numerous articles already written that will get you well on your way.

Upvotes: 0

Mehmet Aras
Mehmet Aras

Reputation: 5374

Are you trying to use IIS instead of the ASP.NET development web server during development? If it is you can go to your web project's settings and then to the web tab to change the development web server to IIS and specify a url. This way you don't need to publish anything, the virtual directory points to your project's folder. So when you compile and run your web application, it will pick up any change. If this is not what you want, you can use msdeploy command line tool in the post-build step to package and deploy/update your web application to local IIS. This way each time you build, msdeploy will run and update IIS with the changes.

Upvotes: 5

JBeckton
JBeckton

Reputation: 7111

This ended up being a lot simpler than I thought. With VS 2010 there is a new feature called "One Click Publish" and there is a toolbar for this as well. I had already created a publish profile for my local iis web so all I have to do is click publish! All of the projects in the solution are then built and published. As long as the projects are all set as dependent then they are built and published along with the web project.

Now all i need it a hot key for one click publish and I am all set.

I would imagine that if I had defined additional build tasks in the csproj file all that would get executed as well.

Upvotes: 3

eaglestorm
eaglestorm

Reputation: 1202

Although I'm using 2008 I found it much easier to use NAnt to build and publish. It allows you much greater flexibility and you can use it to publish to both your local and production site.

Upvotes: 2

Related Questions