WebApplication publish to relative filesystem path

asp.netVisual Studio-2010PublishWeb Application-Project

asp.net Problem Overview


I'm setting up a publish to a relative path for testing locally (especially xml config transformations). Each developer has their own path to the checked out project and I'd like to set up a publish that is machine/environment agnostic.

The publish dialog doesn't hint at any variables or wildcards that are allowed in it and it doesn't accept obj\publish or file://./obj/publish

Is there a way to publish to a relative filesystem path?

asp.net Solutions


Solution 1 - asp.net

For those using Visual Studio 2012 and the new publish configuration file (Properties/PublishProfiles/Local.pubxml) you can use this syntax in the file itself:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <SiteUrlToLaunchAfterPublish />
    <publishUrl>$(MSBuildThisFileDirectory)..\..\obj\publish</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

Be aware that the $(MSBuildThisFileDirectory) property will resolve to the Local.pubxml directory. From there you should traverse up to get where you need to be.

Solution 2 - asp.net

Edit

For Visual Studio 2012, this solution will not work. You should look at the answer by michielvoo just after this one.

Original answer

After trying and trying I found the solution: you can use a relative path by setting

file:///./obj/publish

in the Publish WebApp dialog, but you must use a path that is already existent and writable by the user you are using. This way you can publish your web app in a local folder, or a path related folder.

Let me know if this helps. It did for me.

Solution 3 - asp.net

Just a regular path with forward slashes works in Visual Studio 2012:

../../../../../app

This starts at the published project's root directory.

Solution 4 - asp.net

This worked for me in Visual Studio 2013:

file:\\..\..\..\Publish

Please note that this doesn't publish to obj\publish, as the original poster wanted, but to another directory (a few folders up) on my system as I desired. Modify it for obj\publish if you wish.

Solution 5 - asp.net

VS 2015 accepts something like

..\..\..\DeployFiles

It will also create the folder if it is missing so your publish settings can go into source control but you can easily ignore the DeployFiles folder and its contents.

Solution 6 - asp.net

For the case where an additional post publish step needs to call msdeploy (MSVS 2015, dnx) with a relative path, another alternative is to edit project file (not the pubxml although that may work too) and create a variable that is the conversion of the relative path into an absolute path.

<Target Name="AfterWebPublish" AfterTargets="WebPublish">
     <!-- 
          msdeploy cannot currently handle relative paths for contentPath so first convert it to an absolute path 
     -->    
	<PropertyGroup>
		<AbsOutDir>$([System.IO.Path]::GetFullPath("$(ProjectDir)$(OutDir)"))</AbsOutDir>
	</PropertyGroup>

    <Exec WorkingDirectory="$(ProjectDir)" Command='call "$(DevEnvDir)..\Tools\vsvars32.bat"' />	
    <Exec WorkingDirectory="$(ProjectDir)" Command='"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy" -verb:sync -source:contentPath="$(AbsOutDir)PublishOutput" -dest:package="$(AbsOutDir)$(MSBuildProjectName).zip"' />
  </Target>

Then $(AbsOutDir) can be used elsewhere as needed (such as for msdeploy contentPath). I don't think it can be entered within the dialog.

From "how-can-i-get-msbuild-to-evaluate-and-print-the-full-path-when-given-a-relative".

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMaslowView Question on Stackoverflow
Solution 1 - asp.netMichiel van OosterhoutView Answer on Stackoverflow
Solution 2 - asp.netmarzapowerView Answer on Stackoverflow
Solution 3 - asp.netDmitriy KorobskiyView Answer on Stackoverflow
Solution 4 - asp.netDeanView Answer on Stackoverflow
Solution 5 - asp.netwingyipView Answer on Stackoverflow
Solution 6 - asp.netcrokusekView Answer on Stackoverflow