Publish Profile not working when building website

2019-04-20 15:32发布

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?

2条回答
贪生不怕死
2楼-- · 2019-04-20 15:50

I had the exact same problem as above. I deleted following key and Automated build started working fine.

**<Content Include="website.publishproj" />**
查看更多
男人必须洒脱
3楼-- · 2019-04-20 15:51

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.

查看更多
登录 后发表回答