Robula
Robula

Reputation: 716

How to get the output path of a .NET Core app via MSBuild?

I have a .NET Core project that targets the .NET Framework as per my project.json file;

"frameworks": {
    "net461": {
      "dependencies": { }
    }
}

I am trying to find a way to copy some (native) dependencies to my output build directory but I am struggling to find the correct way to do it.

When I build this project my output goes to bin\Debug\net461\win7-x64. I'm wondering if there is a method to retrieve the output path? $(TargetDir) gives me my bin\ directory, but is there a variable to retrieve bin\Debug\%FRAMEWORK%\%RUNTIME%?

Also should I be using project.json Scripts over MSBuild?

EDIT - May 2017 Please see my answer below. In short, this was never supported by project.json, however this question is no longer relevant given the deprecation of project.json in VS2017.

Upvotes: 2

Views: 3418

Answers (2)

Robula
Robula

Reputation: 716

EDIT - May 2017

Visual Studio tooling has now moved up to version 15 with the introduction of Visual Studio 2017 and with this release global.json, project.json and .xproj have been phased out in favour of .csproj project files. VS2017 will provide a one-way migration when opening the solution.

See here for migration documentation: https://learn.microsoft.com/en-us/dotnet/articles/core/migration/

See here for a comparison between the two: https://learn.microsoft.com/en-us/dotnet/articles/core/tools/project-json-to-csproj

Upvotes: 5

Pawel
Pawel

Reputation: 31610

You can add a postpublish script to your project.json in which you would copy the native bits to %publish:OutputPath%. Another option is to add the files you want to include to:

"publishOptions": {
  "include": [
    ...

Upvotes: 0

Related Questions