Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>In MSBuild 4.0</strong>, the easiest way is the following:</p> <pre><code>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\your\path')) </code></pre> <p>This method works even if the script is <code>&lt;Import&gt;</code>ed into another script; the path is relative to the file containing the above code.</p> <p>(consolidated from <a href="https://stackoverflow.com/a/4894456/33080">Aaron's answer</a> as well as the last part of <a href="https://stackoverflow.com/a/2421596/33080">Sayed's answer</a>)</p> <hr> <p><strong>In MSBuild 3.5</strong>, you can use the <a href="http://msdn.microsoft.com/en-us/library/bb882668.aspx" rel="noreferrer" title="ConvertToAbsolutePath">ConvertToAbsolutePath</a> task:</p> <pre><code>&lt;Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Test" ToolsVersion="3.5"&gt; &lt;PropertyGroup&gt; &lt;Source_Dir&gt;..\..\..\Public\Server\&lt;/Source_Dir&gt; &lt;Program_Dir&gt;c:\Program Files (x86)\Program\&lt;/Program_Dir&gt; &lt;/PropertyGroup&gt; &lt;Target Name="Test"&gt; &lt;ConvertToAbsolutePath Paths="$(Source_Dir)"&gt; &lt;Output TaskParameter="AbsolutePaths" PropertyName="Source_Dir_Abs"/&gt; &lt;/ConvertToAbsolutePath&gt; &lt;Message Text='Copying "$(Source_Dir_Abs)" to "$(Program_Dir)".' /&gt; &lt;/Target&gt; &lt;/Project&gt; </code></pre> <p>Relevant output:</p> <pre><code>Project "P:\software\perforce1\main\XxxxxxXxxx\Xxxxx.proj" on node 0 (default targets). Copying "P:\software\Public\Server\" to "c:\Program Files (x86)\Program\". </code></pre> <p>A little long-winded if you ask me, but it works. This will be relative to the "original" project file, so if placed inside a file that gets <code>&lt;Import&gt;</code>ed, this won't be relative to that file.</p> <hr> <p><strong>In MSBuild 2.0</strong>, there is an approach which doesn't resolve "..". It does however behave just like an absolute path:</p> <pre><code>&lt;PropertyGroup&gt; &lt;Source_Dir_Abs&gt;$(MSBuildProjectDirectory)\$(Source_Dir)&lt;/Source_Dir_Abs&gt; &lt;/PropertyGroup&gt; </code></pre> <p>The <a href="http://msdn.microsoft.com/en-us/library/ms164309%28VS.80%29.aspx" rel="noreferrer">$(MSBuildProjectDirectory)</a> reserved property is always the directory of the script that contains this reference.</p> <p>This will also be relative to the "original" project file, so if placed inside a file that gets <code>&lt;Import&gt;</code>ed, this won't be relative to that file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload