DotNet.Project.LaunchSettings
2.0.1
dotnet add package DotNet.Project.LaunchSettings --version 2.0.1
NuGet\Install-Package DotNet.Project.LaunchSettings -Version 2.0.1
<PackageReference Include="DotNet.Project.LaunchSettings" Version="2.0.1" />
paket add DotNet.Project.LaunchSettings --version 2.0.1
#r "nuget: DotNet.Project.LaunchSettings, 2.0.1"
// Install DotNet.Project.LaunchSettings as a Cake Addin
#addin nuget:?package=DotNet.Project.LaunchSettings&version=2.0.1
// Install DotNet.Project.LaunchSettings as a Cake Tool
#tool nuget:?package=DotNet.Project.LaunchSettings&version=2.0.1
DotNet.Project.LaunchSettings
Parses Visual Studio launchSettings.json
Why does this exist?
I have a suite of acceptance tests that interact with authenticated environments. The tests get the logon details from environment variables, because I'd rather manage those secrets in my build system instead of a configuration file.
Occasionally I need to investigate issues in these environments and need the logon
details. I don't want to edit environment variables when I test different environments,
so instead I keep those logon details in the launchSettings.json
of the acceptance
tests project. (.gitignore this file if you want to do the same.)
async Task Example()
{
var launchSettings = VisualStudioLaunchSettings.FromCaller();
var profiles = launchSettings.GetProfiles();
var profile = profiles.FirstOrEmpty();
var client = await AppEnvironment.FromEnvironment(profile.EnvironmentVariables).CreateClient();
// use the client
}
How to use it?
There are two ways I use this library. If you want to use it, first you need to add it to your project - you can find it on Nuget
First profile
Just grab the first one.
var launchSettings = VisualStudioLaunchSettings.FromCaller();
var profiles = launchSettings.GetProfiles();
var profile = profiles.FirstOrEmpty();
Really simple if you have one, but if you have many and don't want to use a named profile,
you can use this dotnet cli command to (I've lost the link) you'll have to order you profiles.
Named profile
If you intend to use a named profile, you need to ensure it exists before you attempt to use it.
var launchSettings = VisualStudioLaunchSettings.FromCaller();
var profiles = launchSettings.GetProfiles();
var (exists, profile) = profiles.Use("does-not-exist");
// Check exists before you use it!
Match
Theres is alternative syntax to deconstructing the values - invoking Match() instead:
var launchSettings = VisualStudioLaunchSettings.FromCaller();
var profiles = launchSettings.GetProfiles();
profiles
.Use("does-not-exist")
.Match(
() => { Console.WriteLine($"The profile does not exist."); },
profile => { Console.WriteLine($"The profile exists."););
There is a functional version too:
var launchSettings = VisualStudioLaunchSettings.FromCaller();
var profiles = launchSettings.GetProfiles();
var profile = profiles
.Use("does-not-exist")
.Match(() => default, (Profile x) => x);
Note Regarding Versioning
The project uses GitVersion. Versions are bumped by including +semver:{n}
, where {n}
is major, minor or patch, in the commit message. See GitVersion configuration documentation.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Text.Json (>= 6.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.