Is there a way how to find out that the current environment in .NET MAUI is development ?
Because before in my Blazor WASM I did just:
builder.HostEnvironment.IsDevelopment()
But in MauiAppBuilder I dont see any environment property.
Well what I usually do for this is I use the if directive
So for instance if I wanna check if wanna set a different value to var in release than in debug I would do something like below :
#if DEBUG
var a = "debug";
#elif RELEASE
var a = "release"
#endif
Good luck hope this helps
Related
How to set debug level when deploying using Azure ARM template with C#
var deployment = azure.Deployments.Define(parameters.DeploymentName)
.WithExistingResourceGroup(parameters.ResourceGroupName)
.WithTemplate(vmTemplate)
.WithParameters(deploymentParameters)
.WithMode(DeploymentMode.Complete)
.Create();
In Powershell, there is an option we can use:
New-AzureRmResourceGroupDeployment -deploymentdebuglevel
source
As Suggested by mtz1406 you can try checking the below debug setting class in ARM template.
public class DebugSetting
Inherite the object as debug
Here is the Microsoft Documentation for Debug class setting.
I am trying to get access to some docker environment variables in my C# code running on .Net Core.
In my dockerfile generated by VS, I added environment variables like this:
ENV EnvKey = "value"
After building this image and starting the instance with the built-in Docker startup option in VS, I inspect my docker image with docker inspect MyInstance.
The resulting output lists my previously defined environment variable in "Config" -> "Env" -> "EnvKey", so I'm sure it is there.
For some testing, I try to access them with the following code:
var keys = Environment.GetEnvironmentVariables();
However, this does not retrieve the environment variable that is contained in the container.
What else do I need to configure to get this working?
The problem was very simple actually - In my case, this wasn't visible from the question.
But my real environment variable key had some "." in it. I replaced those with "_" and now it works perfectly.
If you are running an ASP.NET application, then updating the Dockerfile to ENV ASPNETCORE_EnvKey = "value" should do the trick for you.
If you are running some other .NET core app on your machine, then look at the docs here. It would seem you can't do this on the machine level, but in your RUN command, you would have to pass the 'environment variables' to the process through the dotnet command you are invoking there.
I have simple code with compiler directive in my WPF app:
#if (DEBUG)
MySettings.Default.Host = "http://localhost:63372/";
#else
MySettings.Default.Host = "http://example.com/";
#endif
All works fine in the Visual Studio. When I switch to Release or Debug then Host filled properly. But when I make publish, in the decompiler I see that Host is equal to "http://localhost:63372/" string.
Where is a problem?
Have you tried:
#if (DEBUG)
MySettings.Default.Host = "http://localhost:63372/";
#endif
#if (!DEBUG)
MySettings.Default.Host = "http://example.com/";
#endif
I have found the anwser. When you publish with clickOnce it uses current selected mode. So, I need to switch to release and then click Publish.
This question already has answers here:
How do I check the active solution configuration Visual Studio built with at runtime?
(4 answers)
Closed 9 years ago.
I have a C# windows application with 4 App Modes - Debug,Pre-Release, Release and UAT. I have to display in the footer of my main form as to what is my current Operating mode. Any idea how I can retrieve the same?
You could use C#'s #if directive http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx
string mode;
#if DEBUG
mode = "DEBUG";
#elseif RELEASE
mode = "RELEASE";
#else
mode = "UAT";
#end
You would also need to set up the symbol in the project file so that the code can pick up on it. You'll find it by selecting the project properties. (Select the project file and press Alt+Enter)
Visual Studio doesn't provide for applying the configuration names to your .NET code.
However, you may want to define a custom symbol for each of your configurations in your project build settings and query these symbols in your code, like this:
#if DEBUG
...
#elif PRERELEASE
...
#elif RELEASE
...
#elif UAT
...
#endif
you must use #if reference.
check http://msdn.microsoft.com/tr-tr/library/4y6tbswk.aspx
I need to use C# on Mac, and I have Mono.
What command line tools are for building purposes Mono/C#?
Can I just use make?
Or is there any tool for that just like Ant for Java?
It looks like the Mono project has its own version of MSBuild, xBuild.
There is NAnt. Development of NAnt starts to get faster again, so we'll see a new release soon ;)
-sa
On *nix platforms, you can simply use make to build and deploy your .NET libraries/applications.
It works quite well and is what Mono itself does when you build from source. Mono will first build mcs and then use the newly built mcs to build the framework assemblies.
My vote for rake:
Home
Tutorial
Rake and c#
You can create a task like this:
SRC = FileList[ '*.cs']
FULL_NAME = "foo.exe"
TARGET = 'library|winexe|exe'
REFS = ["a.dll","b.dll"]
...
task :compile do
sh "#{CSC} -debug -out:#{FULL_NAME} -target:#{TARGET} -lib:#{BUILD_DIR}-r:#{REFS.join(',')} #{SRC}"
end