Web Deploy - Using Relative Paths for local file system deployment
Asked Answered
K

1

26

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

Kohinoor answered 19/8, 2012 at 5:47 Comment(1)
possible duplicate of WebApplication publish to relative filesystem pathScission
R
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 :) ].

Rightwards answered 19/8, 2012 at 18:44 Comment(8)
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?Sensory
I just updated the example to use $(MSBuildThisFileDirectory) which is always relative to the .pubxml file itself. Please use that instead.Rightwards
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?Rostellum
That should fix it. The fix will be in VS Update 2.Rightwards
@SayedIbrahimHashimi I'm just trying it on VS 2012 Update 3 with $(MSBuildProjectDirectory) and that's resolving to the location of the .pubxml fileGreyhound
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).Pedo
@Greyhound 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.Rightwards
Beware of using MSBuildThisProjectDirectory from the above comment, the MSBuildThisFileDirectory referred to in the answer is the setting to useVogeley

© 2022 - 2024 — McMap. All rights reserved.