Search code examples
asp.netmsbuildmsdeploy

MSBUILD script building solution, but not deploying publishing profile


I have created a publishing profile for my web page, and I can successfully publish using the web deploy interface in Visual Studio (right click project, deploy etc). It builds the project on my local PC, and copies the files across to destination IIS server.

But now I am trying to create a MSBuild command, which should do the same, but it is only building the solution, not copying it across to the server.

My MSbuild command looks like this, and I run it from the solution source directory

msbuild "test.co.za.sln" p:DeployOnBuild=true /p:PublishProfile="test.co.za"  /p:UserName="domain\test"  /p:Password="test"

Is there anything wrong with my build command? As you can see in the screenshot, it is building successfully, but no files are being copied across. Which makes me wonder if the publishing profile is executed at all. I have tried various combinations of publishprofile paths, full paths, with extensions, without, nothing seems to copy my files accross.

enter image description here

My publishing profile looks like this App_Data\Publishprofile\test.co.za.pubxml

<?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <WebPublishMethod>MSDeploy</WebPublishMethod>
        <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
        <SiteUrlToLaunchAfterPublish>http://test.co.za</SiteUrlToLaunchAfterPublish>
        <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
        <MSDeployServiceURL>test.co.za</MSDeployServiceURL>
        <DeployIisAppPath>test.co.za</DeployIisAppPath>
        <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
        <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
        <UserName>domain\test</UserName>
        <_SavePWD>True</_SavePWD>
      </PropertyGroup>
    </Project>

EDIT: This is an existing classic ASP website which I added to a solution, it doesn't contain a ".csproj" file, just a "website.publishproj", which doesn't seem to execute


Solution

  • Looks like my "website.publishingproj" is never being built when I run the msbuild command. Not sure why, @Sayed do you perhaps know?

    I had to create a targets file next to my solution called "after.solutionName.sln.targets" and copy the code from this answer : https://stackoverflow.com/a/15138373/1184603

    <!--?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>
    

    It now publishes correctly from my msbuild script.