Setting environment variable for build based on configuration

How do I set environment variable for build for each configuration?
I would like to use local project instead of nuget package for some configurations. In csproj file I have

<ItemGroup Condition="'$(LOCAL_API)' != ''">
<PackageReference Include="Cord" Version="0.0.24" />
<ItemGroup Condition="'$(LOCAL_API)' == ''">
<ProjectReference Include="../../api/API/Cord.csproj" />

But when I set env variable in configuration it's runtime only and it does not apply for build process.


Hello Rene,

To set a variable for the solution you may want to pass it right to the MSBuild in Preferences > Build, Execution, Deployment > Toolset and Build > MSBuild Global Properties > Edit and then + sign. Then fill in name and value of the variable.

Please inform me if that solution help you.



I need also to set environment variables and read them during the build in the csproj file. I can't find the Preferences menu.

I am using Rider v2013.1.3

Thank you


Hello Yiyi Chen,

Please try then Settings > Build, Execution, Deployment > Toolset and Build > MSBuild Global Properties > Edit. It should be available on your version of Rider. After that please use the instructions I sent you before and please let me know if that helped. 

Looking forward to hearing from you soon.


This is unfortunately useless because I would need to switch between targets as fast as possible. But I solved it by creating multiple csproj files which is not the best solution but it fills the purpose.


Hello Anna Morozyuk,

thank you for your reply.

The solution that you suggested worked, but unfortunately my use case required more flexibility: I have .Net Angular SPA project where I created multiple Angular application and I want to run either one or the other. So I need to pass info like the application name, folder and port. So I can't open the settings every time I want to change the application to run. The idea was to create different Run/Debug configurations for the same project but it didn't find a way to make it work.

Can Rider maybe read these environment variables from a .env file?

For the moment I am playing with some bash script to run before build to generate the necessary configuration files and create a .env would be a problem.

More info on my use case here.


Hello Yiyi Chen and Rene,

Thank you for describing your cases in detail.

At the moment it is not possible to configure it in any other way, except for  MSBuild Global Properties. We have a feature request though with the ID RIDER-19129. Please upvote it or press the Watch issue button to receive further updates. 

Thank you for understanding. Have a nice day! 


Please sign in to leave a comment.