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

时光总嘲笑我的痴心妄想 提交于 2019-11-29 04:34:48

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:

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%

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!