Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish Profile not working when building website project

I recognized that Web Deployment Projects are not supported in Visual Studio 2012. After reading this article, I tried to get Publish Profiles to work.

After installing Visual Studio Web Publish Update I was able to publish web site projects and web application projects with the new publish dialog in Visual Studio 2012.

Because we are using TFS 2010 Team Build I tried to use publish profile via MSBuild parameters. But the following statement only works to publish web application projects.

MSBuild.exe MyWebs.sln /p:Configuration=Release /p:DeployOnBuild=true;PublishProfile=DeployToDirectory.pubxml

If I try to publish website projects nothing happens. The publish profile of my website projects only works with the new publish dialog in Visual Studio 2012 but not when calling MSBuild.

Any idea?

like image 243
Thomas Jeitner Avatar asked Jan 18 '13 09:01

Thomas Jeitner


People also ask

Where is publish profile?

Publish profile files are named <profilename>. pubxml and are located in the PublishProfiles folder. The PublishProfiles folder is under Properties in a C# web application project, under My Project in a VB web application project, or under App_Data in a web site project.


1 Answers

I have spent about 3 weeks wrestling with this in my own environment and think I have a solution.

I think the issue is that the website.publishproj file is never actually built when you pass in the solution. I managed to resolve this by doing the following:

  1. Please make sure you are using the new ASP.Net and Tools 2012.2 update. Download Here.
  2. Create a file next to the solution file called after.MyWebs.sln.targets. This file should look as follows:

    <!--?xml version="1.0" encoding="utf-8"?-->
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <Target Name="Deploy Website" AfterTargets="Build">
            <Message Text="Starting Website deployment" Importance="high">
            </Message>
            <MSBuild Projects="$(MSBuildProjectDirectory)\MyWebs\website.publishproj" 
            BuildInParallel="true" /> 
        </Target>
    </Project>
    

What this does is that when MSBuild starts building the solution file, it actually creates an MSBuild file in memory with the extension metaproj. There are ways to get MSBuild to save this file to disk so that you can inspect it but that is easily found on google. The file created in step one is injected into the metaproj file and is run after the build.

This was the only way I could get the new Publish Profiles to give me the output that I used to get with the old Web Deployment Propjects.

Word of warning: If you want to use this in a TFS build, then in this scenario, you will get a _PublishedWebsites folder in the drop location independent of the PublishUrl you specify in the pubxml file. This is something I am trying to resolve but so far, not having much joy.

like image 55
gregpakes Avatar answered Oct 06 '22 10:10

gregpakes