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

前提是你 提交于 2019-11-30 07:34:50

问题


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?


回答1:


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%



回答2:


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.



来源:https://stackoverflow.com/questions/35287635/post-build-event-depending-on-configuration-name-in-new-asp-net-5-project

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