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
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNet.Project.LaunchSettings" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNet.Project.LaunchSettings --version 2.0.1
#r "nuget: DotNet.Project.LaunchSettings, 2.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 51,802 8/24/2022
2.0.0 1,977 8/22/2022
1.2.2 3,477 6/24/2022
1.2.1 8,486 2/10/2020
1.2.0 2,681 2/24/2019
1.1.0 622 2/23/2019
1.0.1 584 2/10/2019
1.0.0 562 2/10/2019