3

I am experimenting with creating a .Net Core Project, which is a NETStandard.Library version 1.6.0.

I wanted to experiment with a post build command, but I noticed now that in our project.json file, there is a "postcompile" script that can be created.

Here is the documentation. https://learn.microsoft.com/en-us/dotnet/articles/core/tools/project-json

I have created a .cmd file, that I am calling from the json file like so:

"scripts": {
"postcompile": ["copyFiles.cmd"]

}

In my cmd file I can have a simple copy command, which works:

xcopy /y "C:\Playground\test.txt" "C:\Playground\test\"

What I am stuck on, is what variables are now available to me at this point, to give me access to things like the build output directory? I can't find a reference to this anywhere.

Thanks in advance.

Sanket
  • 19,295
  • 10
  • 71
  • 82
C. Moore
  • 93
  • 8

1 Answers1

4

Full list of context variables that you can use to control flow in your scripts is:

Every script block:

%project:Directory%
%project:Name%
%project:Version%

Compile specific:

%compile:TargetFramework%
%compile:FullTargetFramework%
%compile:Configuration%
%compile:OutputFile%
%compile:OutputDir%
%compile:ResponseFile%
%compile:RuntimeOutputDir% (only available if there is runtime output)
%compile:RuntimeIdentifier% (only availabe if there is runtime output)
%comiple:CompilerExitCode% (only available in the postcompile script block)

Publish specific:

%publish:ProjectPath%
%publish:Configuration%
%publish:OutputPath%
%publish:TargetFramework%
%publish:FullTargetFramework%
%publish:Runtime%

References:

https://github.com/aspnet/Home/wiki/Project.json-file#scripts

Post build event depending on configuration name in new ASP.NET 5 project

Community
  • 1
  • 1
Sanket
  • 19,295
  • 10
  • 71
  • 82
  • Thank you, that is a very helpful list. I have noticed that I can get these working if my script is directly within my json file. However if I put my script into a .cmd file, it no longer seems to know what %compile:OutputDir% is anymore, and my script no longer works. Any clue how to get them working in a cmd file? – C. Moore Aug 23 '16 at 23:00
  • Sorry.. no idea on that – Sanket Aug 24 '16 at 03:10
  • No I didn't end up getting the cmd file to work unfortunately – C. Moore Aug 29 '16 at 07:30
  • @C.Moore you can pass the `cmd` needed parameters by command line such as `myscript.cmd %compile:OutputDir%` and in the script access them using `$1`,`$2`,... – Tomer W Jan 30 '17 at 11:42