How to run scripts based on solution configuration in ASP.NET Core

。_饼干妹妹 提交于 2019-11-29 05:45:44

You can use %compile:Configuration% to get the current Configuration. Here is the list of variables available to precompile and postcompile scripts.

To actually limit the creation of the nuget package based on the configuration, you'll need to pass it into a script, like this makeNuget.cmd file which I store at the root of my project:

@Echo off
IF "%1" == "%2" dotnet pack --no-build --configuration %1 -o ../%3

Then, in my project.json, I have:

  "scripts": {        
    "postcompile": [
      "makeNuget.cmd %compile:Configuration% Release \\packages\\%project:Name%"
    ]
  }

This creates the nuget package and places it in my solution level packages/[project name] folder (though you may need to adjust the relative folder reference in the -o parameter depending on your solution layout). Also, you don't need the .cmd, by default .cmd is inferred for windows and .sh for other environments.

I also made the target configuration a parameter so that the script is generic and can be used regardless of the configuration name I've chosen as my 'release' config.

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