[英]VS2017 .Net Core (Full Framework) Project's Post Build Event gets empty string for $(ConfigurationName)
I'm setting up the dev environment for a new project. 我正在为一个新项目设置开发环境。 It's a Web API project that serves an @angular project from static files. 这是一个Web API项目,可通过静态文件提供@angular项目。 In order to facilitate this, on post build, I run the angular cli's build function, then copy the files into wwwroot. 为了简化此操作,在构建后,我运行angular cli的构建功能,然后将文件复制到wwwroot。 That's all working fine. 一切都很好。
However, I want to be able to have two different npm scripts run depending on whether the project is in Debug or Release mode. 但是,我希望能够运行两个不同的npm脚本,具体取决于项目是处于Debug还是Release模式。 In my post build scripts, I tried this: 在我的帖子构建脚本中,我尝试了以下操作:
if "$(ConfigurationName)" == "Debug"
(
npm run build
)
else if "$(ConfigurationName)"=="Release"
(
npm run prod
)
but I'm getting 但我越来越
The command "if "" == "Debug"
(
npm run build
)
else if ""=="Release"
(
npm run prod
)" exited with code 255.
It looks like there's no value being provided for ConfigurationName. 似乎没有为ConfigurationName提供任何值。 I've tried both debug and release mode and get the same error. 我已经尝试了调试和发布模式,并得到相同的错误。 Did the ConfigurationName variable change in VS 2017 or something? VS 2017中的ConfigurationName变量是否发生了变化?
EDIT: However, if I click Edit Post-build and then click Macros, I can see here that ConfigurationName has a value. 编辑:但是,如果我单击编辑后生成,然后单击宏,我可以在这里看到ConfigurationName有一个值。 It's just not seen by my script 我的脚本没看到
$(Configuration)
likely works in your case since it is given a value early enough in the build process. $(Configuration)
可能适用于您的情况,因为在构建过程中足够早地为其提供了值。
Pre & Post build events don't really work with "SDK-based" projects (without modification) since most of the properties aren't defined when the build event properties are evaluated. 之前和之后的构建事件实际上不适用于“基于SDK”的项目(未经修改),因为在评估构建事件属性时未定义大多数属性。 See https://github.com/dotnet/project-system/issues/1569 for more details. 有关更多详细信息,请参见https://github.com/dotnet/project-system/issues/1569 。
I recommend doing the following in your project: 我建议在您的项目中执行以下操作:
<Project Sdk="...">
<!-- other content -->
<Target Name="RunNpmBuild" BeforeTargets="BeforeBuild" Condition="'$(Configuration)' != 'Release'">
<Exec Command="npm run build" />
</Target>
<Target Name="RunNpmProd" BeforeTargets="BeforeBuild" Condition="'$(Configuration)' == 'Release'">
<Exec Command="npm run prod" />
</Target>
</Project>
Note that in 1.0.*
CLIs, files generated during build which did not exist before may not be published - see https://github.com/aspnet/websdk/issues/114 for workarounds. 请注意,在1.0.*
CLI中,构建期间生成的以前不存在的文件可能不会发布-有关变通办法,请参见https://github.com/aspnet/websdk/issues/114 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.