Web Deploy - Using Relative Paths for local file system deployment

11,340

We have a bug here, when publishing using File system you have to provide a full path. We actually found this bug earlier this week. It will be fixed in our next update. In this case when the relative path is passed it incorrectly thinks that its an IIS path.

As a workaround you can edit the .pubxml to make the publishUrl a fullpath. Fortunately you can use an MSBuild property so that this works in team scenarios. Here is what you should do, edit your .pubxml file and update the value of publishUrl to be the following.

<publishUrl>$(MSBuildThisFileDirectory)..\..\..\Deploy_Production</publishUrl>

This path will be relative to the .pubxml file itself. I've verified that this works from both the command line as well as the publish dialog. If you have any issues with this let me know, but the fix should hopefully be released in a few months [no guarantees of course :) ].

Share:
11,340

Related videos on Youtube

Doug
Author by

Doug

Can haz codeseses

Updated on June 13, 2022

Comments

  • Doug
    Doug almost 2 years

    I am wanting to use Web Deploy to run a custom deployment setup.

    As I am wanting to have this work fine when running on many different environments (team members local machines, 4 different builds servers) I want to deploy to a local path that is relative.

    What I am wanting to do is:

    • Deploy to a local relative path
    • Have the after build step do magical things...

    However when i enter the local file path to deploy to as: "..\Deploy_Production"

    web deploy complains with this:

    2>Connecting to ..\Deploy_Live...
    2>Unable to create the Web site '../Deploy_Live'.  The URL http://:0 is invalid.
    

    Its as if Web deploy thinks that the relative file path is a website URL. Using "..\" instead doesn't help my cause.

    How do you get WebDeploy to deploy to a local relative path?

    Edit 1:

    I have tried to use a ConvertToAbsolutePath task before build, to no avail:

      <PropertyGroup>
        <WebPublishMethod>FileSystem</WebPublishMethod>
        <SiteUrlToLaunchAfterPublish>http://mywebsite.com</SiteUrlToLaunchAfterPublish>
        <publishUrl>..\Deploy_Production</publishUrl>
        <DeleteExistingFiles>False</DeleteExistingFiles>
      </PropertyGroup>
    
      <Target Name="BeforeBuild">
        <ConvertToAbsolutePath Paths="$(publishUrl)">
          <Output TaskParameter="AbsolutePaths" PropertyName="publishUrl" />
        </ConvertToAbsolutePath>
      </Target>
    

    Edit 2: The above works, but only when running commandline builds against the Solution file not a project file

  • Joseph Sturtevant
    Joseph Sturtevant over 11 years
    I'm getting some very strange behavior when I try to implement this approach. When I run MSbuild from the command line, this works as you describe. When I run it from the Publish Web dialog in VS2012, it appears to interpret MSBuildProjectDirectory as <ProjectDir>\Properties\PublishProfiles. Any guesses?
  • Sayed Ibrahim Hashimi
    Sayed Ibrahim Hashimi over 11 years
    I just updated the example to use $(MSBuildThisFileDirectory) which is always relative to the .pubxml file itself. Please use that instead.
  • Taudris
    Taudris about 11 years
    I think this is the update that fixes this issue? msdn.microsoft.com/en-us/library/jj161045.aspx Is this going to be released as a proper VS2012 update?
  • Sayed Ibrahim Hashimi
    Sayed Ibrahim Hashimi about 11 years
    That should fix it. The fix will be in VS Update 2.
  • Farinha
    Farinha over 10 years
    @SayedIbrahimHashimi I'm just trying it on VS 2012 Update 3 with $(MSBuildProjectDirectory) and that's resolving to the location of the .pubxml file
  • Jeff Dege
    Jeff Dege almost 10 years
    Just playing around with this in VS2013. Tried using $(SolutionDir) and $(ProjectDir). $(ProjectDir) worked the way I'd have expected it to, but $(SolutionDir) published things to the same place as $(SolutionDir).
  • Sayed Ibrahim Hashimi
    Sayed Ibrahim Hashimi almost 10 years
    @Farinha as I stated don't use MSBuildProjectDirectory in the .pubxml. Instead always use MSBuildThisProjectDirectory. The value foe MPD will be different in VS versus MSBuild.
  • Patrick McDonald
    Patrick McDonald almost 10 years
    Beware of using MSBuildThisProjectDirectory from the above comment, the MSBuildThisFileDirectory referred to in the answer is the setting to use