❔ getting sensitive config from .csproj
I would like to get some env vars in csproj, however when defining them in an ItemGroup I get compilation errors - msbuild error: specify the name of the target.
Presumably it's something obvious, but I can't find it.. :
7 Replies
I've never heard of setting env vars in the csproj before, and even if you could that would be a bad idea
that means having secrets in your checked in source
that exactly prevents checking them in source as they're just references, i.e. $(EMAIL_USERNAME)
Ah, I see, you want to read the value in the csproj.. but that is a bit weird too, what would
<Email__Host>
do?
thats not a standard property of a project file
if you want to get the value ofEMAIL_USERNAME
inside your program, just use var emailUsername = System.Environment.GetEnvironmentVariable("EMAIL_USERNAME");
it returns string?
there are also libraries to let you use .env files, if you want that, or to register your environment variables as configuration options in the standard .net config systemNow that you mention it - indeed why not just use System.Environment.GetEnvironmentVariable - no need to modify csproj. I think I got derailed as I originally wanted different envs for prod and dev, but again - just getting env vars directly could be enough
side point: I dont recommend using EFCore 8 preview with .net 7 🙂
so downgrade to 7.0.4, or upgrade your .NET to the .8 preview
ah thanks - will do that as well
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.