25

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

Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178
Doug
  • 6,460
  • 5
  • 59
  • 83
  • possible duplicate of [WebApplication publish to relative filesystem path](http://stackoverflow.com/questions/6587254/webapplication-publish-to-relative-filesystem-path) – fretje Jul 30 '15 at 15:29

1 Answers1

45

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 :) ].

Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178
  • 1
    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 \Properties\PublishProfiles. Any guesses? – Joseph Sturtevant Sep 21 '12 at 16:25
  • 9
    I just updated the example to use $(MSBuildThisFileDirectory) which is always relative to the .pubxml file itself. Please use that instead. – Sayed Ibrahim Hashimi Sep 21 '12 at 23:03
  • I think this is the update that fixes this issue? http://msdn.microsoft.com/en-us/library/jj161045.aspx Is this going to be released as a proper VS2012 update? – Taudris Mar 27 '13 at 01:20
  • That should fix it. The fix will be in VS Update 2. – Sayed Ibrahim Hashimi Mar 27 '13 at 04:49
  • 1
    @SayedIbrahimHashimi I'm just trying it on VS 2012 Update 3 with $(MSBuildProjectDirectory) and that's resolving to the location of the .pubxml file – Farinha Sep 20 '13 at 14:54
  • 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). – Jeff Dege May 23 '14 at 21:43
  • @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. – Sayed Ibrahim Hashimi May 23 '14 at 23:29
  • 2
    Beware of using MSBuildThisProjectDirectory from the above comment, the MSBuildThisFileDirectory referred to in the answer is the setting to use – Patrick McDonald Jun 19 '14 at 14:54