0

I tried using the Environment Variable APSNETCORE_ENVIRONMENT in my csproj file as a condition. But it doesn't seem to work.

The code:

<Target Name="NpmInstall" Inputs="$(SpaRoot)/package.json" Outputs="$(SpaRoot)/node_modules/.install-stamp" Condition="$(ASPNETCORE_ENVIRONMENT) != 'Development'">
  • Does that environment variable exist to begin with? That environment variable is meant to specify the ASP.NET Core *runtime* environment. A project file will never be deployed to a production server (I hope). If you want to execute different steps for different builds, use different *configurations* beyond Debug/Release or different profiles – Panagiotis Kanavos Mar 17 '22 at 10:03
  • YES IT EXISTS! I specified it in the Properties Tab in Visual Studio. I want to use another variable, but I wanted to try it with one that I know exists! – user3315635 Mar 17 '22 at 10:10
  • So *it doesn't exist* and your answer confirms this. The environment variables in the Debug tab are applied to the already compiled application being debugged. They don't change your machine's environment variables. It *is* possible to specify extra environment variables that affect the build process – Panagiotis Kanavos Mar 17 '22 at 10:56

2 Answers2

0

NVM, appereantly msbuild only takes the system variables but not the ones defined in the debug tab. Solved it by adding my desired variable to the Global Environment Variables.

  • There are no "global" or "debug" environment variables. Environment variables are part of the *environment* used to run any application. It's possible to specify extra environment variables when starting a new process. The settings in the `Debug` tab are only used when *debugging* the application, not when building it. When the debugger starts the already compiled application, it adds any environment variables to the application's process. – Panagiotis Kanavos Mar 17 '22 at 10:50
  • You can specify extra environment variables that affect the build, eg as a pre-build step, or using the appropriate MSBuild target [as shown here](https://stackoverflow.com/questions/14267938/msbuild-how-to-set-environment-variables). – Panagiotis Kanavos Mar 17 '22 at 11:00
0

Try to wrap the variable in single quotes in the condition, like

Condition="'$(ASPNETCORE_ENVIRONMENT)' != 'Development'">
Alex
  • 114
  • 5