Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the value of MSBuildThisFileDirectory?

If I have a project structure like this:

\MySolution
  \MyProject
    ReadMe.md
    \build
      MyProject.targets

What would the value of $(MSBuildThisFileDirectory) be when used in the MyProject.targets file?

Assuming my solution folder is in the root of C: drive, would it be?..

c:\MySolution\MyProject\build\

In the MyProject.targets file, how would I reference the ReadMe.md file using the $(MSBuildThisFileDirectory)?

Additional information:

MyProject.targets looks like:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <None Include="$(MSBuildThisFileDirectory)\xxx\ReadMe.md">
      <Link>FrameworkTests.feature</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CustomToolNamespace></CustomToolNamespace>
    </None>
  </ItemGroup>
</Project>
like image 806
Matt W Avatar asked Apr 12 '18 11:04

Matt W


People also ask

What is MSBuildProjectDirectory?

MSBuildProjectDirectory is the property that will give you the full path to the project file which was invoked on the command line.

What is build props file?

The “build. prop” file is a system file that contains build properties and settings. Some of the contents are specific to your device or your device's manufacturer, others vary by version of the operating system, but some are generic to all devices running the same version of Android as you are.

What is the use of directory build props?

Directory. Build. props is a user-defined file that provides customizations to projects under a directory.

How do I create a build property in Microsoft?

MSBuild lets you set properties on the command line by using the -property (or -p) switch. These global property values override property values that are set in the project file. This includes environment properties, but does not include reserved properties, which cannot be changed.


1 Answers

What is the value of MSBuildThisFileDirectory?

It depends on your MyProject.targets. According to the literal meaning of this variable, you could to know ThisFileDirectory means "This File Directory".

Since you have use this argument in the file MyProject.targets, the path should be related to the location of the "this file" MyProject.targets. So the value of this argument should be the directory of this file MyProject.targets.

After install the nuget, the file MyProject.targets should be added to the path:

c:\MySolution\packages\MyProject.1.0.0<YouPackagefolder>\build

You can use a target to output that value in your project file, to accomplish this, unload your project. Then at the very end of the project, just before the end-tag </project>, place below scripts:

  <Target Name="TestValue" AfterTargets="build">
    <Message Text="@(none)">
    </Message>
  </Target>
like image 178
Leo Liu-MSFT Avatar answered Sep 20 '22 12:09

Leo Liu-MSFT