4

I have a web application project in Visual Studio 2010, which has MS Deploy options configured for it. I can right click the project in Solution Explorer and kick-off "Build Deployment Package" which tells MSDeploy to create a deployment zip file. That internally depends on the Build target for the project. All that works.

Trouble is, I can't see how to get the MSDeploy packaging functionality to run as part of the Build target in Visual Studio. In other words, when I right click the project in Solution Explorer, and click plain old "Build," I'd like for it to also do the "Build Deployment Package."

"Why not just click Build Deployment Package, then", you ask? Because I really want the build target of my web application to be a dependency of another project in my solution which is a WIX installer. In other words, the WIX project has a single dependency which is my web application project. When I Build the WIX project, VS automatically builds the web application project, but does not build the deployment package. The WIX installer is using the deployment package as part of its installation process. In this workflow, either the WIX installer project will fail to build because it can't find files created by MSDeploy (bad), or it will find a stale MSDeploy package and use that without complaining (really bad). Sounds redundant to use both MSDeploy and Microsoft Installer, but I am taking queues from here. I like the idea of having an MSI that can be chained with other MSIs or incorporated into a GPO application.

If I simply try to manually add "Package" as a post build event to the web application project by inserting this into the raw csproj XML:

<Target Name="AfterBuild">
   <CallTarget Targets="Package" />
</Target>

then the plain old build will fail because it will then depend on Package, and apparently the Package target depends on Build. Which is circular.

Maybe what I really, really want is a way to tell the WIX installer project to depend on the output of the "Build Deployment Package" target, or the Solution to use "Build Deployment Package" rather than "Build" in its Project dependency graph. Any ideas on that?

I do not think I want an MSBuild script that must be executed from the commandline, as when performing a scheduled TFS TeamBuild. I'd like to keep this as a VisualStudio task executed by a developer (me) with a monitor, keyboard and mouse randomly and many times a day. In fact, I want to say that I don't have access to TFS at all.

3 Answers 3

3

Okay, so to answer my own question...

Just add ";Package" to the list of default build targets at the very top of the project file in question as in:

<Project ToolsVersion="4.0" DefaultTargets="Build;Package" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

That is line 2 of my csproj file. Now, when you click "Build," the project also performs the MSDeploy Packaging target. And, when another project depends on this web application project, and the other project is built normally through VS, the MSDeploy packaging target is executed in due course.

And all is right with the world. Why was that so hard to research, and why should I have to manually edit the Project file to accomplish this? Don't answer that.

Sign up to request clarification or add additional context in comments.

Comments

2

Adding the "Package" Target works great until you want to use different Publish Profiles. I found that you can add the Publish Profile as a property group item in your .csproj file like below:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
  <PlatformTarget>$(Platform)</PlatformTarget>
  <PublishProfile>ServerDebug</PublishProfile>
   ...
</PropertyGroup>

Do the above for each Configuration/Platform Combination and set the to be the desired Profile.

Comments

1

Add the following property to the MSBuild arguments:

/property:DeployOnBuild=true

1 Comment

I'm not sure how this figures into the plain-old Visual Studio GUI, without launching a commandline and invoking msbuild from there. I was hoping to accomplish this from within the VS GUI as I am lazy, and there is a build button there already.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.