Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebApplication publish to relative filesystem path

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?

like image 346
Maslow Avatar asked Jul 05 '11 18:07

Maslow


People also ask

What is a relative path to a file?

Relative Path is the hierarchical path that locates a file or folder on a file system starting from the current directory. The relative path is different from the absolute path, which locates the file or folder starting from the root of the file system.

How do I find the relative path of a folder?

var relativePath = Path. GetRelativePath( @"C:\Program Files\Dummy Folder\MyProgram", @"C:\Program Files\Dummy Folder\MyProgram\Data\datafile1. dat"); In the above example, the relativePath variable is equal to Data\datafile1.


2 Answers

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.

like image 177
Michiel van Oosterhout Avatar answered Oct 21 '22 13:10

Michiel van Oosterhout


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.

like image 18
marzapower Avatar answered Oct 21 '22 13:10

marzapower