Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm writing a unified project for 3 smart TVs. I have also 3 configurations created in Visual Studio. Now I want to execute some CLI scripts depending on selected configuration.

The problem is in new ASP.NET 5 project I don't have an editor for post build events.

I know I have to do this in project.json. What I found is:

  "scripts": {
    "postbuild": ""
  }

But using this one I can't create different CLI scripts for different configurations.

I found also:

  "configurations": {
  },

And I guess this is probably what I want, but... How to use it? Intellisense has no power here and also I wasn't lucky searching the Web...

[edit]

Maybe I should try with .xproj?

like image 369
Nickon Avatar asked Feb 09 '16 08:02

Nickon


2 Answers

You'll need to build a master script which uses the available context and environment variables to switch and run the other scripts of your choice.

In addition to the list of variables Here for compile, you also get these for publish related scripts and then these are available everywhere, as are environment variables returned by Environment.GetEnvironmentVariable, which can be seen here.

The image below shows the intellisense from the VS2015 Update 3 RTM, but it's misleading, since you get others depending on the script block you're using:

enter image description here

So, your 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%
like image 136
Erikest Avatar answered Sep 30 '22 17:09

Erikest


I investigated on this a bit but did not really get to any good result.

There are some project variables that are exposed in scripts. Unfortunately, those are very limited:

  • %project:Name% gives you the project name
  • %project:Directory% gives you the project directory
  • %project:Version% gives you the project version

So there is no way to access the build configuration or the environment here.

The configurations option in the project.json is also limited to build configurations and only allows declaring compilation options there, so that also doesn’t work.

Unfortunately, there also doesn’t seem to be another way to solve this. At least not right now. I would consider myself sending a pull request to DNX to add some additional project variables which one could use but at the moment, it doesn’t really make any sense to invest time into DNX: After all it’s being replaced by the dotnet CLI. We’ll see if that one will come with functionality to access the environment—and if not, I might end up submitting a pull request to add this functionality. But until we get there, I’m afraid there is no solution for this.

like image 36
poke Avatar answered Sep 30 '22 17:09

poke