简体   繁体   English

VS2017 .Net Core(完整框架)项目的后构建事件获取$(ConfigurationName)的空字符串

[英]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 我的脚本没看到

  1. $(Configuration) likely works in your case since it is given a value early enough in the build process. $(Configuration)可能适用于您的情况,因为在构建过程中足够早地为其提供了值。

  2. 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.

相关问题 安装vs2017后无法打开vs2015 .net core 1.1项目 - Unable to open vs2015 .net core 1.1 project after installing vs2017 在 VS 2017 中针对完整的 .net 框架 asp.net 核心项目运行 XUnit 2.2.0 单元测试时出现 System.BadImageFormatException - System.BadImageFormatException when running XUnit 2.2.0 unit test in VS 2017 against a full .net framework asp.net core project 使用TFS 2012构建服务器构建VS2017项目 - Build VS2017 project with TFS 2012 build server 使用VS2017制作框架(不是核心,不是标准)NuGet软件包 - Making Framework (not Core, not Standard) NuGet packages with VS2017 VS2017 .Net Core 2性​​能和负载测试 - VS2017 .Net Core 2 performance and load test 将 .net 5.0 程序集添加到项目 VS2017.Net 4.7 - adding .net 5.0 assembly to project VS2017 .Net 4.7 VS2017 CSPROJ项目中的Nuget打包 - Nuget packaging in VS2017 csproj project 如何在VS2017中引用.net项目中的netstandard项目? - How do you reference a netstandard project from .net project in VS2017? 无法在VS2017下的IISExpress下运行.Net Core应用 - Unable to run .Net Core app under IISExpress under VS2017 VS2017-Framework 4.6.2在c#中的类库项目中未显示为选项,但在vb Windows窗体中 - VS2017 - Framework 4.6.2 is not shown as an option in a class library project in c#, but it is in a vb windows forms one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM