<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.2">Jekyll</generator><link href="https://bryanknox.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://bryanknox.github.io/" rel="alternate" type="text/html" /><updated>2022-07-16T01:57:41+00:00</updated><id>https://bryanknox.github.io/feed.xml</id><title type="html">Knoxbits Blog</title><subtitle>I love software development. It makes me happy.</subtitle><author><name>Bryan Knox</name></author><entry><title type="html">_FunctionsSkipCleanOutput and FunctionsPreservedDependencies</title><link href="https://bryanknox.github.io/2022/07/15/functionsskipcleanoutput-and-functionspreserveddependencies.html" rel="alternate" type="text/html" title="_FunctionsSkipCleanOutput and FunctionsPreservedDependencies" /><published>2022-07-15T07:00:00+00:00</published><updated>2022-07-15T07:00:00+00:00</updated><id>https://bryanknox.github.io/2022/07/15/functionsskipcleanoutput-and-functionspreserveddependencies</id><content type="html" xml:base="https://bryanknox.github.io/2022/07/15/functionsskipcleanoutput-and-functionspreserveddependencies.html">&lt;p&gt;It is common to run into ‘&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Could not load file or assembly&lt;/code&gt;’ errors when developing 
in-process Azure Functions.&lt;/p&gt;

&lt;p&gt;For example, “&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Message: Could not load file or assembly 'Microsoft.IdentityModel.Protocols, ...&lt;/code&gt;”
or “&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Message: Could not load file or assembly 'Microsoft.IdentityModel.Protocols.OpenIdConnect, ...&lt;/code&gt;”.&lt;/p&gt;

&lt;p&gt;These errors are typically emitted when a function is triggered. Hopefully during development and not in production.&lt;/p&gt;

&lt;p&gt;Here’s a full example of the error logged:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[2021-07-18T19:40:20.200Z] Authorization Failed. System.IO.FileNotFoundException caught while validating JWT token.Message: Could not load file or assembly 'System.IdentityModel.Tokens.Jwt, Version=6.7.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Both the name and version of the assembly in the error message are important to understanding what’s gone wrong.&lt;/p&gt;

&lt;h2 id=&quot;the-problem&quot;&gt;The Problem&lt;/h2&gt;
&lt;p&gt;These errors are typically caused by the in-process Azure Functions runtime when it tries to remove what it believes are redundant assemblies. The runtime includes a bunch of assemblies that it uses. By default it will remove assemblies from the function app that have the same name as assemblies it already has. The runtime is doing that to help improve performance and reduce space.&lt;/p&gt;

&lt;p&gt;That behavior doesn’t cause any problem when the assemblies being removed are the same versions as those used by the runtime. But that behavior becomes a problem for the function app developer when version is different that what the runtime is using.&lt;/p&gt;

&lt;p&gt;Note that these problems don’t occur in isolated process (out-of-process) Azure Functions because the runtime runs in a separate process than the function app and doesn’t muck with its assemblies.&lt;/p&gt;

&lt;h2 id=&quot;fixes&quot;&gt;Fixes&lt;/h2&gt;

&lt;p&gt;There are two mechanisms that can be used to fix this problem without playing games with the version of the assemblies or NuGet packages that the function app depends on. Both of these require edits to the function app’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.csproj&lt;/code&gt; file.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Skip Cleanout (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_FunctionsSkipCleanOutput&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Preserve Dependencies (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FunctionsPreservedDependencies&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;skip-cleanout-_functionsskipcleanoutput&quot;&gt;Skip Cleanout (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_FunctionsSkipCleanOutput&lt;/code&gt;)&lt;/h3&gt;

&lt;p&gt;Add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;_FunctionsSkipCleanOutput&amp;gt;true&amp;lt;/_FunctionsSkipCleanOutput&amp;gt;&lt;/code&gt; to a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; in the function
app’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.csproj&lt;/code&gt; file. The runtime will now skip removing redundant assemblies das part of its clean out process.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;
&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;_FunctionsSkipCleanOutput&amp;gt;&lt;/span&gt;true&lt;span class=&quot;nt&quot;&gt;&amp;lt;/_FunctionsSkipCleanOutput&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;preserve-dependencies-functionspreserveddependencies&quot;&gt;Preserve Dependencies (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FunctionsPreservedDependencies&lt;/code&gt;)&lt;/h3&gt;

&lt;p&gt;Add one or more &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FunctionsPreservedDependencies&lt;/code&gt; elements to an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;ItemGroup&amp;gt;&lt;/code&gt; in the function app’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.csproj&lt;/code&gt; file. That tells the runtime not to remove the specified assembly as part of its clean out process.&lt;/p&gt;

&lt;p&gt;You’ll need to add one &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;FunctionsPreservedDependencies&amp;gt;&lt;/code&gt; element for each assembly that the runtime would otherwise be removed by the runtime. That includes assemblies that are indirectly included by your project. So assemblies used by the assemblies your function app uses.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;
&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;ItemGroup&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;FunctionsPreservedDependencies&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Include=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Microsoft.IdentityModel.JsonWebTokens.dll&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;FunctionsPreservedDependencies&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Include=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Microsoft.IdentityModel.Logging.dll&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;FunctionsPreservedDependencies&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Include=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Microsoft.IdentityModel.Protocols.dll&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;FunctionsPreservedDependencies&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Include=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Microsoft.IdentityModel.Protocols.OpenIdConnect.dll&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;FunctionsPreservedDependencies&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Include=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Microsoft.IdentityModel.Tokens.dll&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;FunctionsPreservedDependencies&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Include=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;System.IdentityModel.Tokens.Jwt.dll&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/ItemGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hunting down the assembly names to list in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FunctionsPreservedDependencies&lt;/code&gt; elements
can be time consuming. You’ll need to rebuild and trigger each of functions in the function app to see if you’ve found all of them.&lt;/p&gt;

&lt;p&gt;That list will need to be updated as the assemblies or the version of the assemblies used by the function app or the runtime change.&lt;/p&gt;

&lt;p&gt;There is a list of assemblies that the in-process Azure Functions runtime uses. That list is maintained at:
https://github.com/Azure/azure-functions-host/blob/dev/tools/ExtensionsMetadataGenerator/test/ExtensionsMetadataGeneratorTests/ExistingRuntimeAssemblies.txt&lt;/p&gt;

&lt;h2 id=&quot;which-fix-to-use&quot;&gt;Which fix to Use?&lt;/h2&gt;

&lt;p&gt;A dev/devops team might decide between skip cleanout and preserving specific assemblies base on the amount of efficiency they desired in the runtime environments for their function app, and on their capacity to handle additional maintenance.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_FunctionsSkipCleanOutput&lt;/code&gt; - Use skip cleanout if efficiency-loss due to multiple assemblies being deployed is not a concern. Skipping cleanout doesn’t require additional potential maintenance over time.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FunctionsPreservedDependencies&lt;/code&gt; - Use preserve dependencies if efficiency is important, and worth the cost of the updating the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FunctionsPreservedDependencies&lt;/code&gt; elements as the function app or runtime evolve.&lt;/p&gt;

&lt;h2 id=&quot;testing-the-fix&quot;&gt;Testing the Fix&lt;/h2&gt;
&lt;p&gt;No matter which mechanism you chose to fix the problem, you should test the fix by triggering/testing each function in your function app. Or at least those that depend on different assemblies.&lt;/p&gt;

&lt;h1 id=&quot;documentation-none&quot;&gt;Documentation (none)&lt;/h1&gt;

&lt;p&gt;As of the writing of this post there is no official documentation for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_FunctionsSkipCleanOutput&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FunctionsPreservedDependencies&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There was some info for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FunctionsPreservedDependencies&lt;/code&gt; &lt;a href=&quot;https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-vs#configure-your-build-output-settings&quot;&gt;here&lt;/a&gt; but the “Configure your build output settings” section, where it was mentioned, has been removed. Sad.&lt;/p&gt;

&lt;p&gt;There was &lt;a href=&quot;https://github.com/MicrosoftDocs/azure-docs/pull/77460&quot;&gt;an attempt to add some documentation&lt;/a&gt; but it was shot down.&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/bryanknox/AzureFunctionsOpenIDConnectAuthSample/issues/27&quot;&gt;https://github.com/bryanknox/AzureFunctionsOpenIDConnectAuthSample/issues/27&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/Azure/azure-functions-vs-build-sdk/issues/397&quot;&gt;https://github.com/Azure/azure-functions-vs-build-sdk/issues/397&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/Azure/azure-functions-host/issues/7061&quot;&gt;https://github.com/Azure/azure-functions-host/issues/7061&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/Azure/azure-functions-host/blob/dev/tools/ExtensionsMetadataGenerator/test/ExtensionsMetadataGeneratorTests/ExistingRuntimeAssemblies.txt&quot;&gt;https://github.com/Azure/azure-functions-host/blob/dev/tools/ExtensionsMetadataGenerator/test/ExtensionsMetadataGeneratorTests/ExistingRuntimeAssemblies.txt&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/MicrosoftDocs/azure-docs/pull/77460&quot;&gt;https://github.com/MicrosoftDocs/azure-docs/pull/77460&lt;/a&gt;&lt;/p&gt;</content><author><name>Bryan Knox</name></author><summary type="html">It is common to run into ‘Could not load file or assembly’ errors when developing in-process Azure Functions.</summary></entry><entry><title type="html">dotnet user-secrets set CLI Notes</title><link href="https://bryanknox.github.io/2021/12/09/dotnet-user-secrets-set-cli-notes.html" rel="alternate" type="text/html" title="dotnet user-secrets set CLI Notes" /><published>2021-12-09T08:00:00+00:00</published><updated>2021-12-09T08:00:00+00:00</updated><id>https://bryanknox.github.io/2021/12/09/dotnet-user-secrets-set-cli-notes</id><content type="html" xml:base="https://bryanknox.github.io/2021/12/09/dotnet-user-secrets-set-cli-notes.html">&lt;p&gt;In this post I try to provide some helpful information that is not currently included in the &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets#secret-manager&quot;&gt;official documentation&lt;/a&gt; for the ASP.NET Core’s .NET CLI Secret Manager tool’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets set&lt;/code&gt; command.&lt;/p&gt;

&lt;h3 id=&quot;series-aspnet-core-secret-manager-tool&quot;&gt;Series: ASP.NET Core Secret Manager tool&lt;/h3&gt;

&lt;p&gt;This post is part of a series about the ASP.NET Core Secret Manager tool that includes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/07/dotnet-user-secrets-cli-notes.html&quot;&gt;dotnet user-secrets CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/08/dotnet-user-secrets-init-cli-notes.html&quot;&gt;dotnet user-secrets init CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/09/dotnet-user-secrets-set-cli-notes.html&quot;&gt;dotnet user-secrets set CLI Notes&lt;/a&gt; (this post)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;table-of-contents&quot;&gt;Table of Contents&lt;/h2&gt;

&lt;!-- Start Document Outline --&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#dotnet-user-secrets-set&quot;&gt;dotnet user-secrets set&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#applicable-versions&quot;&gt;Applicable Versions&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#concepts&quot;&gt;Concepts&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#synopsis&quot;&gt;Synopsis&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#description&quot;&gt;Description&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#arguments&quot;&gt;Arguments&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#options&quot;&gt;Options&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#help-option&quot;&gt;Help Option&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#configuration-option&quot;&gt;Configuration Option&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#id-option&quot;&gt;Id Option&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#project-option&quot;&gt;Project Option&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#verbose-option&quot;&gt;Verbose Option&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#examples&quot;&gt;Examples&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#default-project-and-configuration&quot;&gt;Default project and configuration&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#piped-input&quot;&gt;Piped Input&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#see-also&quot;&gt;See also&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#other-documentation&quot;&gt;Other Documentation&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#acknowledgments&quot;&gt;Acknowledgments&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;!-- End Document Outline --&gt;

&lt;h2 id=&quot;dotnet-user-secrets-set&quot;&gt;dotnet user-secrets set&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets set&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets set&lt;/code&gt; command is used to set the value of a named secret in a user secrets store.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets set&lt;/code&gt; command is part of ASP.NET Core’s .NET CLI &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets#secret-manager&quot;&gt;Secret Manager tool&lt;/a&gt; tool.&lt;/p&gt;

&lt;h3 id=&quot;applicable-versions&quot;&gt;Applicable Versions&lt;/h3&gt;
&lt;p&gt;This article applies to: .NET 6.x SDK and later versions.&lt;/p&gt;

&lt;p&gt;The notes in this post are based on my observations and experiments using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; CLI tool version: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.0.0-rtm.21526.8+ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;concepts&quot;&gt;Concepts&lt;/h2&gt;

&lt;p&gt;See the &lt;strong&gt;Concepts&lt;/strong&gt; section of &lt;a href=&quot;/2021/12/07/dotnet-user-secrets-cli-notes.html&quot;&gt;dotnet user-secrets CLI Notes&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;synopsis&quot;&gt;Synopsis&lt;/h2&gt;

&lt;p&gt;General synopsis:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Usage: dotnet user-secrets set [arguments] [options]

Arguments:
  [name]   Name of the secret
  [value]  Value of the secret

Options:
  -?|-h|--help                        Show help information
  -v|--verbose                        Show verbose output
  -p|--project &amp;lt;PROJECT&amp;gt;              Path to project. Defaults to searching the current directory.
  -c|--configuration &amp;lt;CONFIGURATION&amp;gt;  The project configuration to use. Defaults to 'Debug'.
  --id &amp;lt;USERSECRETSID&amp;gt;                The user secrets ID to use.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Synopsis for various options:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets set [name] [value]
    [-p|--project &amp;lt;PROJECT&amp;gt;]
    [-c|--configuration &amp;lt;CONFIGURATION&amp;gt;]

dotnet user-secrets set [name] [value]
    --id &amp;lt;USERSECRETSID&amp;gt;

dotnet user-secrets set -?|-h|--help
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;description&quot;&gt;Description&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets set&lt;/code&gt; command is used to set the value of a named secret in a user secrets store.&lt;/p&gt;

&lt;p&gt;The user secrets store to be operated on can be specified in two different ways:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Directly using the &lt;a href=&quot;#id-option&quot;&gt;Id Option&lt;/a&gt; to specify the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Indirectly via a Visual Studio project file. The project file in the current directory is used by default, as is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Debug&lt;/code&gt; configuration within the project file. See &lt;a href=&quot;#project-option&quot;&gt;Project Option&lt;/a&gt; and &lt;a href=&quot;#configuration-option&quot;&gt;Configuration Option&lt;/a&gt; below for info on how to override those defaults.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The user secrets store will be created if it does not already exist.&lt;/p&gt;

&lt;h2 id=&quot;arguments&quot;&gt;Arguments&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[name] [value]&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[name]&lt;/code&gt;  - Name of the secret to set.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[value]&lt;/code&gt; - Value to set for the named secret.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;options&quot;&gt;Options&lt;/h2&gt;

&lt;h3 id=&quot;help-option&quot;&gt;Help Option&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-?|-h|--help&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Show help information for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets set&lt;/code&gt; command.&lt;/p&gt;

&lt;h3 id=&quot;configuration-option&quot;&gt;Configuration Option&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-c|--configuration &amp;lt;CONFIGURATION&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Specifies the configuration in the Visual Studio project file that the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; to use should be associated with.&lt;/p&gt;

&lt;p&gt;Defaults to the configuration named “Debug”.&lt;/p&gt;

&lt;p&gt;Ignored if any id option is specified.&lt;/p&gt;

&lt;p&gt;The Visual Studio project file’s global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; will be used if the specified configuration is not associated with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; in the project file. In that scenario an error will be output if the project file does not have a global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;id-option&quot;&gt;Id Option&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--id &amp;lt;USERSECRETSID&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Specifies the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; of the user secrets store to operate on.&lt;/p&gt;

&lt;p&gt;If an id option is specified, then the tool will ignore any project option, configuration option, and it will not look for a Visual Studio project file.&lt;/p&gt;

&lt;h3 id=&quot;project-option&quot;&gt;Project Option&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-p|--project &amp;lt;PROJECT&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Specifies the path to the Visual Studio project file on the local machine that should be used to determine the user secrets store to operate on.&lt;/p&gt;

&lt;p&gt;Defaults to searching the current directory on the local machine for the Visual Studio project.&lt;/p&gt;

&lt;p&gt;Ignored if any id option is specified.&lt;/p&gt;

&lt;h3 id=&quot;verbose-option&quot;&gt;Verbose Option&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-v|--verbose&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Show verbose information in the command’s output.&lt;/p&gt;

&lt;p&gt;The verbose information includes:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Project file path.&lt;/li&gt;
  &lt;li&gt;Secrets file path.&lt;/li&gt;
  &lt;li&gt;Additional error and diagnostic details for MSBuild related errors.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;h3 id=&quot;default-project-and-configuration&quot;&gt;Default project and configuration&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets set ConnectionString &quot;User ID=bob;Password=***&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Sets the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ConnectionString&lt;/code&gt; secret to the value &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;User ID=bob;Password=***&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Because no project option was specified, the command looks in the Visual Studio project file in the current directory on the local machine.&lt;/p&gt;

&lt;p&gt;No configuration option is specified, so the command looks in the project file for the configuration named “Debug” and uses the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; associated with that configuration. If no &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; is associated with the Debug configuration in the project file, then the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; in the project file that is NOT associated with any particular configuration is used. That is referred to as the project’s global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;. If global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; cannot be found then an error like the following is output.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Could not find the global property 'UserSecretsId' in MSBuild project 'D:\Tests\MyProject\MyProject.csproj'. Ensure this property is set in the project or use the '--id' command line option.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;piped-input&quot;&gt;Piped Input&lt;/h3&gt;

&lt;p&gt;The command will accept piped input. Piped input is expected to be in valid JSON format.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;type .\my-secrets.json | dotnet user-secrets set
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;see-also&quot;&gt;See also&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/07/dotnet-user-secrets-cli-notes.html&quot;&gt;dotnet user-secrets CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/08/dotnet-user-secrets-init-cli-notes.html&quot;&gt;dotnet user-secrets init CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;other-documentation&quot;&gt;Other Documentation&lt;/h3&gt;

&lt;p&gt;As of this posting the best/only documentation I could find is the following in Microsoft Docs:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-6.0&amp;amp;tabs=windows#secret-manager&quot;&gt;Secret Manager&lt;/a&gt; section of &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-6.0&amp;amp;tabs=windows&quot;&gt;Safe storage of app secrets in development in ASP.NET Core&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;acknowledgments&quot;&gt;Acknowledgments&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Special thanks to &lt;a href=&quot;https://stackoverflow.com/users/134204/panagiotis-kanavos&quot;&gt;Panagiotis Kanavos&lt;/a&gt; whose &lt;a href=&quot;https://stackoverflow.com/a/60438095/575113&quot;&gt;answer on Stack Overflow&lt;/a&gt; provided the information I needed to understand the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--configuration&lt;/code&gt; option behaves for most of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; commands.&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Bryan Knox</name></author><summary type="html">In this post I try to provide some helpful information that is not currently included in the official documentation for the ASP.NET Core’s .NET CLI Secret Manager tool’s dotnet user-secrets set command.</summary></entry><entry><title type="html">dotnet user-secrets init CLI Notes</title><link href="https://bryanknox.github.io/2021/12/08/dotnet-user-secrets-init-cli-notes.html" rel="alternate" type="text/html" title="dotnet user-secrets init CLI Notes" /><published>2021-12-08T08:00:00+00:00</published><updated>2021-12-08T08:00:00+00:00</updated><id>https://bryanknox.github.io/2021/12/08/dotnet-user-secrets-init-cli-notes</id><content type="html" xml:base="https://bryanknox.github.io/2021/12/08/dotnet-user-secrets-init-cli-notes.html">&lt;p&gt;In this post I try to provide some helpful information that is not currently included in the &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets#secret-manager&quot;&gt;official documentation&lt;/a&gt; for the ASP.NET Core’s .NET CLI Secret Manager tool’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init&lt;/code&gt; command.&lt;/p&gt;

&lt;h3 id=&quot;series-aspnet-core-secret-manager-tool&quot;&gt;Series: ASP.NET Core Secret Manager tool&lt;/h3&gt;

&lt;p&gt;This post is part of a series about the ASP.NET Core Secret Manager tool that includes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/07/dotnet-user-secrets-cli-notes.html&quot;&gt;dotnet user-secrets CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/08/dotnet-user-secrets-init-cli-notes.html&quot;&gt;dotnet user-secrets init CLI Notes&lt;/a&gt;  (this post)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/09/dotnet-user-secrets-set-cli-notes.html&quot;&gt;dotnet user-secrets set CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;table-of-contents&quot;&gt;Table of Contents&lt;/h2&gt;

&lt;!-- Start Document Outline --&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#dotnet-user-secrets-init&quot;&gt;dotnet user-secrets init&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#applicable-versions&quot;&gt;Applicable Versions&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#concepts&quot;&gt;Concepts&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#synopsis&quot;&gt;Synopsis&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#description&quot;&gt;Description&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#configuration-specific-user-secrets&quot;&gt;Configuration-specific User Secrets&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#options&quot;&gt;Options&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#help-option&quot;&gt;Help Option&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#configuration-option&quot;&gt;Configuration Option&lt;/a&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#manually-adding-configuration-specific-usersecretsids&quot;&gt;Manually adding Configuration-specific UserSecretsIds&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#my-configuration-option-wish&quot;&gt;My configuration option wish&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#id-option&quot;&gt;Id Option&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#project-option&quot;&gt;Project Option&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#verbose-option&quot;&gt;Verbose Option&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#examples&quot;&gt;Examples&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#initialize-using-defaults&quot;&gt;Initialize using defaults&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#specify-visual-studio-project-to-initialize&quot;&gt;Specify Visual Studio project to initialize&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#specify-custom-user-secrets-id&quot;&gt;Specify custom user secrets ID&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#visual-studio-projects-with-propertygroup-condition-attributes&quot;&gt;Visual Studio projects with PropertyGroup Condition attributes&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#see-also&quot;&gt;See also&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#other-documentation&quot;&gt;Other Documentation&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#acknowledgments&quot;&gt;Acknowledgments&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;!-- End Document Outline --&gt;

&lt;h2 id=&quot;dotnet-user-secrets-init&quot;&gt;dotnet user-secrets init&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init&lt;/code&gt; command is used to initialize or update a Visual Studio project file so that the project can use secrets stored in a user secrets store.&lt;/p&gt;

&lt;p&gt;The command is part of ASP.NET Core’s .NET CLI &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets#secret-manager&quot;&gt;Secret Manager tool&lt;/a&gt; tool.&lt;/p&gt;

&lt;h3 id=&quot;applicable-versions&quot;&gt;Applicable Versions&lt;/h3&gt;
&lt;p&gt;This article applies to: .NET 6.x SDK and later versions.&lt;/p&gt;

&lt;p&gt;The notes in this post are based on my observations and experiments using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; CLI tool version: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.0.0-rtm.21526.8+ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;concepts&quot;&gt;Concepts&lt;/h2&gt;

&lt;p&gt;See the &lt;strong&gt;Concepts&lt;/strong&gt; section of &lt;a href=&quot;/2021/12/07/dotnet-user-secrets-cli-notes.html&quot;&gt;dotnet user-secrets CLI Notes&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;synopsis&quot;&gt;Synopsis&lt;/h2&gt;

&lt;p&gt;General synopsis:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Usage: dotnet user-secrets init [options]

Options:
  -?|-h|--help                        Show help information.
  -v|--verbose                        Ignored.
  -p|--project &amp;lt;PROJECT&amp;gt;              Path to project. Defaults to searching the current directory.
  -c|--configuration &amp;lt;CONFIGURATION&amp;gt;  Ignored.
  --id &amp;lt;USERSECRETSID&amp;gt;                The user secrets ID to use.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Synopsis for various options:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets init
    [--id &amp;lt;USERSECRETSID&amp;gt;]
    [-p|--project &amp;lt;PROJECT&amp;gt;]

dotnet user-secrets init -?|-h|--help
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;description&quot;&gt;Description&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init&lt;/code&gt; command is used to initialize or update a Visual Studio project file so that the project can use secrets stored in a user secrets store.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; command does NOT create a user secrets store.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The command &lt;em&gt;adds&lt;/em&gt; or &lt;em&gt;updates&lt;/em&gt; the Visual Studio project file’s &lt;em&gt;global&lt;/em&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/code&gt; element in the first &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; element in the Visual Studio project file that does not have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Condition&lt;/code&gt; attribute.&lt;/p&gt;

&lt;p&gt;If no &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; element exists in the project file, or if all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; elements have &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Condition&lt;/code&gt; attributes, then a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; element (with no &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Condition&lt;/code&gt; attribute) is added to the project file, and the  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/code&gt; element is added to it.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/code&gt; element’s inner text is initialized to new GUID by default, unless a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; is specified by the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--id &amp;lt;USERSECRETSID&amp;gt;&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;If the &lt;a href=&quot;#project-option&quot;&gt;Project Option&lt;/a&gt; is not specified then the tool searches the current directory for the Visual Studio project file.&lt;/p&gt;

&lt;h3 id=&quot;configuration-specific-user-secrets&quot;&gt;Configuration-specific User Secrets&lt;/h3&gt;

&lt;p&gt;The global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; added or updated in the project by the tool is independent of any configuration associated with the project. It will be used by any configuration that does not have an associated &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; setup in the project file.&lt;/p&gt;

&lt;p&gt;If you want to use configuration-specific user secrets stores, then you’ll need to manually add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/code&gt; elements to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; elements that have &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Condition&lt;/code&gt; attributes the associate the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; with the configuration.&lt;/p&gt;

&lt;p&gt;See the &lt;a href=&quot;#configuration-option&quot;&gt;Configuration Option&lt;/a&gt; section below for more info.&lt;/p&gt;

&lt;h2 id=&quot;options&quot;&gt;Options&lt;/h2&gt;

&lt;h3 id=&quot;help-option&quot;&gt;Help Option&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-?|-h|--help&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Show help information for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init&lt;/code&gt; command.&lt;/p&gt;

&lt;h3 id=&quot;configuration-option&quot;&gt;Configuration Option&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-c|--configuration &amp;lt;CONFIGURATION&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Ignored. Currently (in version &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.0.0-rtm.21526.8+ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52&lt;/code&gt;) the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-c|--configuration &amp;lt;CONFIGURATION&amp;gt;&lt;/code&gt; options seems to be ignored and have no effect on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init&lt;/code&gt; command. &lt;em&gt;Or, it could be that I haven’t figured out how to properly use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--configuration&lt;/code&gt; option with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init&lt;/code&gt; command.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Other &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; commands do support the configuration option.&lt;/p&gt;

&lt;h4 id=&quot;manually-adding-configuration-specific-usersecretsids&quot;&gt;Manually adding Configuration-specific UserSecretsIds&lt;/h4&gt;

&lt;p&gt;If you want to use configuration-specific user secrets stores, then you’ll need to manually edit the Visual Studio project file and add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/code&gt; elements to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; elements with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Condition&lt;/code&gt; attributes that associate the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; with the configuration.&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;OutputType&amp;gt;&lt;/span&gt;Exe&lt;span class=&quot;nt&quot;&gt;&amp;lt;/OutputType&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;TargetFramework&amp;gt;&lt;/span&gt;net5.0&lt;span class=&quot;nt&quot;&gt;&amp;lt;/TargetFramework&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- Global UserSecretsId --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/span&gt;myGlobal-UserSecretsId&lt;span class=&quot;nt&quot;&gt;&amp;lt;/UserSecretsId&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;

  &lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Condition=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;'$(Configuration)'=='TestConfig1'&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- TestConfig1 configuration's  UserSecretsId --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/span&gt;myTestConfig1-UserSecretsId&lt;span class=&quot;nt&quot;&gt;&amp;lt;/UserSecretsId&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt; 

  &lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Condition=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;'$(Configuration)'=='TestConfig2'&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- TestConfig2 configuration's  UserSecretsId --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/span&gt;myNewUserSecretId&lt;span class=&quot;nt&quot;&gt;&amp;lt;/UserSecretsId&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;my-configuration-option-wish&quot;&gt;My configuration option wish&lt;/h4&gt;

&lt;p&gt;I would like to see the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--configuration&lt;/code&gt; options be supported by the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init&lt;/code&gt; command so that it could be used to initialize or update the global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; or a configuration-specific &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The following is a sample Visual Studio project file that has a global &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;, plus configuration-specific user secrets IDs for configurations named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TestConfig1&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TestConfig2&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;OutputType&amp;gt;&lt;/span&gt;Exe&lt;span class=&quot;nt&quot;&gt;&amp;lt;/OutputType&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;TargetFramework&amp;gt;&lt;/span&gt;net5.0&lt;span class=&quot;nt&quot;&gt;&amp;lt;/TargetFramework&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- Global UserSecretsId --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/span&gt;myGlobal-UserSecretsId&lt;span class=&quot;nt&quot;&gt;&amp;lt;/UserSecretsId&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;

  &lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Condition=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;'$(Configuration)'=='TestConfig1'&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- TestConfig1 configuration's  UserSecretsId --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/span&gt;myTestConfig1-UserSecretsId&lt;span class=&quot;nt&quot;&gt;&amp;lt;/UserSecretsId&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt; 

  &lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Condition=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;'$(Configuration)'=='TestConfig2'&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- TestConfig2 configuration's  UserSecretsId --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/span&gt;myTestConfig2-UserSecretsId&lt;span class=&quot;nt&quot;&gt;&amp;lt;/UserSecretsId&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h5 id=&quot;example---update-usersecretsid-for-specified-configuration&quot;&gt;Example - Update UserSecretsId for Specified Configuration&lt;/h5&gt;

&lt;p&gt;The following command would update the sample project above by setting the the user secrets ID in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/code&gt; element within the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; element where Configuration is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TestConfig2&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets init -c TestConfig1 -id myNewUserSecretId
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;id-option&quot;&gt;Id Option&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--id \&amp;lt;USERSECRETSID&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Specifies the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; to be set in the Visual Studio project file.&lt;/p&gt;

&lt;p&gt;If the Id option is not specified then the tool defaults to using a new GUID as the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The specified &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; is set as the inner text of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/code&gt; element added or updated in the Visual Studio project file.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; to used can be simple text, it does not need to be a GUID.&lt;/p&gt;

&lt;p&gt;The user secrets store associated with the specified &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; does not need to already exist.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init&lt;/code&gt; command does NOT create the user secrets store associated with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Currently (version &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.0.0-rtm.21526.8+ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52&lt;/code&gt;) the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; is used in the file path of the user secrets store’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;secret.json&lt;/code&gt; file.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; should &lt;em&gt;contain only valid file path characters&lt;/em&gt; for the operating systems of the machines where the Visual Studio project file will be used.&lt;/p&gt;

  &lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init&lt;/code&gt; command does not enforce that requirement and will succeed in setting a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;, but other &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; commands will produce errors like the following example when they encounter such &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;s.&lt;/p&gt;
  &lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Command failed : Invalid character ':' found in the `UserSecretsId` at index '3'.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
  &lt;p&gt;The limitation is required because in the current Secret Manager tool (version &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.0.0-rtm.21526.8+ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52&lt;/code&gt;) implementation the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; is used to form the file path to the user secrets store’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;secret.json&lt;/code&gt; file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;project-option&quot;&gt;Project Option&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-p|--project &amp;lt;PROJECT&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Path to the Visual Studio project file where the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; will be added or updated.&lt;/p&gt;

&lt;p&gt;If the project option is not specified then the tool defaults to searching the current directory for the Visual Studio project file.&lt;/p&gt;

&lt;h3 id=&quot;verbose-option&quot;&gt;Verbose Option&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-v|--verbose&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Ignored. As of version &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.0.0-rtm.21526.8+ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52&lt;/code&gt;, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-v|--verbose&lt;/code&gt; options seems to be ignored and have no effect on the output of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init&lt;/code&gt; command.&lt;/p&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;h3 id=&quot;initialize-using-defaults&quot;&gt;Initialize using defaults&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Generates a new GUID will be used as the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;TargetFramework&amp;gt;&lt;/span&gt;net6.0&lt;span class=&quot;nt&quot;&gt;&amp;lt;/TargetFramework&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/span&gt;03c27eab-1b9f-40b3-b8a0-2c68b57fe526&lt;span class=&quot;nt&quot;&gt;&amp;lt;/UserSecretsId&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If the Visual Studio project file already has a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;, it will not be updated.&lt;/p&gt;

&lt;h3 id=&quot;specify-visual-studio-project-to-initialize&quot;&gt;Specify Visual Studio project to initialize&lt;/h3&gt;

&lt;p&gt;Use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-p|--project &amp;lt;PROJECT&amp;gt;&lt;/code&gt; option to specify the path to the Visual Studio project files that the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; should be added to.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets init -p D:/repos/my-repos/sample/MyProject/MyProject.cspoj`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;specify-custom-user-secrets-id&quot;&gt;Specify custom user secrets ID&lt;/h3&gt;

&lt;p&gt;Use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--id &amp;lt;USERSECRETSID&amp;gt;&lt;/code&gt; option to specify the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; to add or update in the Visual Studio project file.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets init `--id local-dev-test1`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The following Visual Studio project snippet shows an example of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/code&gt; element that is added or updated. Where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;local-dev-test1&lt;/code&gt; is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; that was specified.&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;TargetFramework&amp;gt;&lt;/span&gt;net6.0&lt;span class=&quot;nt&quot;&gt;&amp;lt;/TargetFramework&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/span&gt;local-dev-test1&lt;span class=&quot;nt&quot;&gt;&amp;lt;/UserSecretsId&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;visual-studio-projects-with-propertygroup-condition-attributes&quot;&gt;Visual Studio projects with PropertyGroup Condition attributes&lt;/h3&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets init --id my-user-secret-id
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the Visual Studio project file, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/code&gt; element is added or updated in the first &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/code&gt; element that does not have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Condition&lt;/code&gt; attribute. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/code&gt; element’s inner text is set to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;my-user-secret-id&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Condition=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;'$(Configuration)'=='Release'&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- First PropertyGroup with a Condition. --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;Condition=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;'$(Configuration)'=='Debug'&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- Second PropertyGroup with a Condition. --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- First PropertyGroup without a Condition. --&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/span&gt;my-user-secret-id&lt;span class=&quot;nt&quot;&gt;&amp;lt;/UserSecretsId&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- Second PropertyGroup without a Condition. --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;see-also&quot;&gt;See also&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/07/dotnet-user-secrets-cli-notes.html&quot;&gt;dotnet user-secrets CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/09/dotnet-user-secrets-set-cli-notes.html&quot;&gt;dotnet user-secrets set CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;other-documentation&quot;&gt;Other Documentation&lt;/h3&gt;

&lt;p&gt;As of this posting the best/only documentation I could find is the following in Microsoft Docs:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-6.0&amp;amp;tabs=windows#secret-manager&quot;&gt;Secret Manager&lt;/a&gt; section of &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-6.0&amp;amp;tabs=windows&quot;&gt;Safe storage of app secrets in development in ASP.NET Core&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;acknowledgments&quot;&gt;Acknowledgments&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Special thanks to &lt;a href=&quot;https://stackoverflow.com/users/134204/panagiotis-kanavos&quot;&gt;Panagiotis Kanavos&lt;/a&gt; whose &lt;a href=&quot;https://stackoverflow.com/a/60438095/575113&quot;&gt;answer on Stack Overflow&lt;/a&gt; provided the information I needed to understand the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--configuration&lt;/code&gt; option behaves for most of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; commands.&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Bryan Knox</name></author><summary type="html">In this post I try to provide some helpful information that is not currently included in the official documentation for the ASP.NET Core’s .NET CLI Secret Manager tool’s dotnet user-secrets init command.</summary></entry><entry><title type="html">dotnet user-secrets CLI Notes</title><link href="https://bryanknox.github.io/2021/12/07/dotnet-user-secrets-cli-notes.html" rel="alternate" type="text/html" title="dotnet user-secrets CLI Notes" /><published>2021-12-07T08:00:00+00:00</published><updated>2021-12-07T08:00:00+00:00</updated><id>https://bryanknox.github.io/2021/12/07/dotnet-user-secrets-cli-notes</id><content type="html" xml:base="https://bryanknox.github.io/2021/12/07/dotnet-user-secrets-cli-notes.html">&lt;p&gt;In this post I try to provide some helpful information that is not currently included in the &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets#secret-manager&quot;&gt;official documentation&lt;/a&gt; for the ASP.NET Core’s .NET CLI &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool (a.k.a. Secret Manager tool).&lt;/p&gt;

&lt;h3 id=&quot;series-aspnet-core-secret-manager-tool&quot;&gt;Series: ASP.NET Core Secret Manager tool&lt;/h3&gt;

&lt;p&gt;This post is part of a series about the ASP.NET Core Secret Manager tool that includes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/07/dotnet-user-secrets-cli-notes.html&quot;&gt;dotnet user-secrets CLI Notes&lt;/a&gt; (this post)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/08/dotnet-user-secrets-init-cli-notes.html&quot;&gt;dotnet user-secrets init CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/09/dotnet-user-secrets-set-cli-notes.html&quot;&gt;dotnet user-secrets set CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;table-of-contents&quot;&gt;Table of Contents&lt;/h2&gt;

&lt;!-- Start Document Outline --&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#dotnet-user-secrets&quot;&gt;dotnet user-secrets&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#applicable-versions&quot;&gt;Applicable Versions&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#secret-manager-vs-secrets-manager&quot;&gt;Secret Manager vs Secrets Manager&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#concepts&quot;&gt;Concepts&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#secrets-and-user-secrets-stores&quot;&gt;Secrets and user secrets stores&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#user-secrets-stores-and-user-secrets-ids&quot;&gt;User secrets stores and user secrets IDs&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#project-files-configurations-and-user-secrets-ids&quot;&gt;Project files, configurations and user secrets IDs&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#synopsis&quot;&gt;Synopsis&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#description&quot;&gt;Description&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#options&quot;&gt;Options&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#commands&quot;&gt;Commands&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#commands-for-managing-user-secrets-ids-in-a-visual-studio-project&quot;&gt;Commands for managing user secrets IDs in a Visual Studio project&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#commands-for-managing-secrets-in-a-user-secrets-store&quot;&gt;Commands for managing secrets in a user secrets store&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#examples&quot;&gt;Examples&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#show-help&quot;&gt;Show Help&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#show-version&quot;&gt;Show Version&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#implementation-details&quot;&gt;Implementation Details&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#secretjson-user-secrets-store&quot;&gt;secret.json user secrets store&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#see-also&quot;&gt;See also&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#other-documentation&quot;&gt;Other Documentation&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#source-code-for-dotnet-user-secrets-tool&quot;&gt;Source Code for dotnet-user-secrets Tool&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#acknowledgments&quot;&gt;Acknowledgments&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;!-- End Document Outline --&gt;

&lt;h2 id=&quot;dotnet-user-secrets&quot;&gt;dotnet user-secrets&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; is a command line tool for managing the set of secrets in a user secrets store, and managing the user secrets store used by a Visual Studio project.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool (a.k.a. &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets#secret-manager&quot;&gt;Secret Manager tool&lt;/a&gt;) is a .NET CLI tool that is part of ASP.NET Core.&lt;/p&gt;

&lt;h3 id=&quot;applicable-versions&quot;&gt;Applicable Versions&lt;/h3&gt;
&lt;p&gt;This article applies to: .NET 6.x SDK and later versions.&lt;/p&gt;

&lt;p&gt;The notes in this post are based on my observations and experiments using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; CLI tool version: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.0.0-rtm.21526.8+ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;secret-manager-vs-secrets-manager&quot;&gt;Secret Manager vs Secrets Manager&lt;/h3&gt;

&lt;p&gt;The &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets#secret-manager&quot;&gt;Microsoft docs&lt;/a&gt; call it “Secret Manager”, while &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets --help&lt;/code&gt; calls it “Secrets Manager”.&lt;/p&gt;

&lt;h2 id=&quot;concepts&quot;&gt;Concepts&lt;/h2&gt;

&lt;h3 id=&quot;secrets-and-user-secrets-stores&quot;&gt;Secrets and user secrets stores&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;A &lt;strong&gt;secret&lt;/strong&gt; has a name and a value.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Sets of secrets are stored in a &lt;strong&gt;user secrets store&lt;/strong&gt;.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;p&gt;The implementation and location of a user secrets store are hidden behind the abstractions provided by the Secret Manager tool. That allows the Secret Manager to be used by developer and code without exposing the implementation details. It also allows the tool to evolve to support user secrets stores in different locations or with different implementations.&lt;/p&gt;

        &lt;ul&gt;
          &lt;li&gt;
            &lt;p&gt;See the &lt;a href=&quot;#implementation-details&quot;&gt;Implementation Details&lt;/a&gt; section below.&lt;/p&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;p&gt;In these notes I use the term “user secrets store” instead of “secrets file” to honor the intended abstractions.&lt;/p&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Each individual secret has a unique name that is used to identify it within the user secrets store.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;user-secrets-stores-and-user-secrets-ids&quot;&gt;User secrets stores and user secrets IDs&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;A &lt;strong&gt;user secrets ID&lt;/strong&gt; is used to identify a user secrets store.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;Developers can specify a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool to manage secrets in the user secrets store associated with that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;project-files-configurations-and-user-secrets-ids&quot;&gt;Project files, configurations and user secrets IDs&lt;/h3&gt;

&lt;p&gt;The user secrets store to be operated on by the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool can be specified in two different ways:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Directly using the Id option to specify the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Indirectly via a Visual Studio project file.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;A &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; can be added to a Visual Studio project file to associate the project with a specific user secrets store.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;When a Visual Studio project file has a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; the project’s code can use secrets in the associated user secrets store via ASP.NET Core’s Secret Manager.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool can read the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; from a specified Visual Studio project file, or the tool can search for a project file from which to read the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;Developers can use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool to manage secrets in the user secrets store associated with the project, without having to explicitly specify the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;A Visual Studio project file can have multiple &lt;strong&gt;configurations&lt;/strong&gt; and each build of the project uses exactly one of the configurations.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;A configuration in a Visual Studio project can be associated with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;. That allows the build of the project for a particular configuration to use secrets from the user secrets store associated with that configuration.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;Developers can specify a configuration to the the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool and it will use it to search the the Visual Studio project file for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; that should be used.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The use of configurations is optional.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;Developers can setup a Visual Studio project file so that the same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; is used regardless of the number of configurations that have been setup for the project.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Configurations are independent of user secrets stores.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;Each configuration can be setup in the project with a different &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;, so that each configuration uses a different store. Or multiple configurations in the same project can use the same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;, so that they use the same user secrets store.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The combination of project and configuration can be used by the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool to determine the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt; to use for accessing the associated user secrets store.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;Projects and configurations are used as shortcuts that can be a convenient way for developers to work with secrets in user secrets stores. Once the project file is setup to associate user secrets IDs with its configurations then the developers can use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool and indicate a configuration. That allows the developer manage the secrets for a particular project configuration without having to remember the specific &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserSecretsId&lt;/code&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;synopsis&quot;&gt;Synopsis&lt;/h2&gt;

&lt;p&gt;General synopsis:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Usage: dotnet user-secrets [command] [options]

Options:
  -?|-h|--help                        Show help information
  --version                           Show version information
  -v|--verbose                        Show verbose output
  -p|--project &amp;lt;PROJECT&amp;gt;              Path to project. Defaults to searching the current directory.
  -c|--configuration &amp;lt;CONFIGURATION&amp;gt;  The project configuration to use. Defaults to 'Debug'.
  --id &amp;lt;USERSECRETSID&amp;gt;                The user secrets ID to use.

Commands:
  clear   Deletes all the secrets in a user secrets store.
  init    Initialize or update a Visual Studio projectto use a specified user secrets store.
  list    Lists secrets in a user secrets store. 
  remove  Removes the specified secret from a user secrets store.
  set     Sets a secret to a specified value in a user secrets store.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Synopsis for usage without a command:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets -?|-h|--help|-v|-verbose

dotnet user-secrets --version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;description&quot;&gt;Description&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool can be used for:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Managing secrets in a user secrets store.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;See &lt;a href=&quot;#commands-for-managing-secrets-in-a-user-secrets-store&quot;&gt;Commands for managing secrets in a user secrets store&lt;/a&gt; below.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Initializing or updating a Visual Studio project file so that the project can use secrets stored a specified user secrets store.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;See &lt;a href=&quot;/2021/12/08/dotnet-user-secrets-init-cli-notes.html&quot;&gt;dotnet user-secrets init CLI Notes&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;options&quot;&gt;Options&lt;/h2&gt;
&lt;p&gt;The options described below are only those for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; when no additional command is specified. For details about options for specific commands, follow the links in the &lt;a href=&quot;#commands&quot;&gt;Commands&lt;/a&gt; section below.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-?|-h|--help&lt;/code&gt;&lt;/p&gt;

    &lt;p&gt;Show dotnet user-secrets tool help information.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--version&lt;/code&gt;&lt;/p&gt;

    &lt;p&gt;Show dotnet user-secrets tool version information.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-v|--verbose&lt;/code&gt;&lt;/p&gt;

    &lt;p&gt;Show verbose output. When no command is specified the output is the same as for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--help&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;commands&quot;&gt;Commands&lt;/h2&gt;

&lt;p&gt;For details about specific commands and their options follow the links below.&lt;/p&gt;

&lt;h3 id=&quot;commands-for-managing-user-secrets-ids-in-a-visual-studio-project&quot;&gt;Commands for managing user secrets IDs in a Visual Studio project&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; - Initialize or update a Visual Studio project file so that the project can use secrets stored a specified user secrets store.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets init [options]&lt;/code&gt;&lt;/p&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;p&gt;See &lt;a href=&quot;/2021/12/08/dotnet-user-secrets-init-cli-notes.html&quot;&gt;dotnet user-secrets init CLI Notes&lt;/a&gt;&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;commands-for-managing-secrets-in-a-user-secrets-store&quot;&gt;Commands for managing secrets in a user secrets store&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clear&lt;/code&gt; - Deletes all the secrets in a user secrets store.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets clear [options]&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list&lt;/code&gt; - Lists secrets in a user secrets store.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets list [options]&lt;/code&gt;`&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;remove&lt;/code&gt; - Removes the specified secret from a user secrets store.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets remove [arguments] [options]&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;set&lt;/code&gt; - Sets a secret to a specified value in a user secrets store.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets set [arguments] [options]&lt;/code&gt;&lt;/p&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;p&gt;See &lt;a href=&quot;/2021/12/09/dotnet-user-secrets-set-cli-notes.html&quot;&gt;dotnet user-secrets set CLI Notes&lt;/a&gt;&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;I haven’t written posts for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;clear&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;remove&lt;/code&gt; commands, but those should be fairly easy to figure out from the information in &lt;a href=&quot;/2021/12/09/dotnet-user-secrets-set-cli-notes.html&quot;&gt;dotnet user-secrets set CLI Notes&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following are examples of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool without a specified command.&lt;/p&gt;

&lt;h3 id=&quot;show-help&quot;&gt;Show Help&lt;/h3&gt;

&lt;p&gt;Show &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool help.&lt;/p&gt;

&lt;p&gt;Command Format:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets -?|-h|--help|-v|-verbose
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;All of the options above the produce same output.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets --help
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;User Secrets Manager 6.0.0-rtm.21526.8+ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52

Usage: dotnet user-secrets [options] [command]

Options:
  -?|-h|--help                        Show help information
  --version                           Show version information
  -v|--verbose                        Show verbose output
  -p|--project &amp;lt;PROJECT&amp;gt;              Path to project. Defaults to searching the current directory.
  -c|--configuration &amp;lt;CONFIGURATION&amp;gt;  The project configuration to use. Defaults to 'Debug'.
  --id                                The user secrets ID to use.

Commands:
  clear   Deletes all the application secrets
  init    Set a user secrets ID to enable secret storage
  list    Lists all the application secrets
  remove  Removes the specified user secret
  set     Sets the user secret to the specified value

Use &quot;dotnet user-secrets [command] --help&quot; for more information about a command.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;show-version&quot;&gt;Show Version&lt;/h3&gt;
&lt;p&gt;Show &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool version information.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet user-secrets --version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Output:&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;User Secrets Manager
6.0.0-rtm.21526.8+ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;implementation-details&quot;&gt;Implementation Details&lt;/h2&gt;

&lt;h3 id=&quot;secretjson-user-secrets-store&quot;&gt;secret.json user secrets store&lt;/h3&gt;

&lt;p&gt;The implementation and location of a user secrets store are hidden behind the abstractions provided by the Secret Manager tool. That allows the Secret Manager to be used by developer and code without exposing the implementation details. It also allows the tool to evolve to support user secrets stores in different locations or with different implementations.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Developers are warned not to write code that depends on the location, storage or implementation details of user secrets stores as those things could changes in the future.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Currently (version &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6.0.0-rtm.21526.8+ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52&lt;/code&gt;) user secrets stores are implemented as JSON files named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;secret.json&lt;/code&gt; that are stored in the local machine’s user profile folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;File system path:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Linux/macOS: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.microsoft/usersecrets/&amp;lt;user_secrets_id&amp;gt;/secrets.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Windows: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%APPDATA%\Microsoft\UserSecrets\&amp;lt;user_secrets_id&amp;gt;\secrets.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;user_secrets_id&amp;gt;&lt;/code&gt; is the user secrets ID that is used to uniquely identify the user secrets store on the local machine.&lt;/p&gt;

&lt;h2 id=&quot;see-also&quot;&gt;See also&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/08/dotnet-user-secrets-init-cli-notes.html&quot;&gt;dotnet user-secrets init CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;/2021/12/09/dotnet-user-secrets-set-cli-notes.html&quot;&gt;dotnet user-secrets set CLI Notes&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;other-documentation&quot;&gt;Other Documentation&lt;/h3&gt;

&lt;p&gt;As of this posting the best/only documentation I could find is the following in Microsoft Docs:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-6.0&amp;amp;tabs=windows#secret-manager&quot;&gt;Secret Manager&lt;/a&gt; section of &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-6.0&amp;amp;tabs=windows&quot;&gt;Safe storage of app secrets in development in ASP.NET Core&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;source-code-for-dotnet-user-secrets-tool&quot;&gt;Source Code for dotnet-user-secrets Tool&lt;/h3&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool (a.k.a. Secret Manager tool) is a .NET CLI tool that is part of ASP.NET Core.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; tool source code is in GitHub as part of  &lt;a href=&quot;https://github.com/dotnet/aspnetcore&quot;&gt;dotnet/aspnetcore&lt;/a&gt; repo, in the &lt;a href=&quot;https://github.com/dotnet/aspnetcore/tree/main/src/Tools/dotnet-user-secrets&quot;&gt;src/Tools/dotnet-user-secrets&lt;/a&gt; folder.&lt;/p&gt;

&lt;h2 id=&quot;acknowledgments&quot;&gt;Acknowledgments&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Special thanks to &lt;a href=&quot;https://stackoverflow.com/users/134204/panagiotis-kanavos&quot;&gt;Panagiotis Kanavos&lt;/a&gt; whose &lt;a href=&quot;https://stackoverflow.com/a/60438095/575113&quot;&gt;answer on Stack Overflow&lt;/a&gt; provided the information I needed to understand the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--configuration&lt;/code&gt; option behaves for most of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dotnet user-secrets&lt;/code&gt; commands.&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Bryan Knox</name></author><summary type="html">In this post I try to provide some helpful information that is not currently included in the official documentation for the ASP.NET Core’s .NET CLI dotnet user-secrets tool (a.k.a. Secret Manager tool).</summary></entry><entry><title type="html">Duplicate Detection for Service Bus output binding in Azure Functions</title><link href="https://bryanknox.github.io/2020/04/01/duplicate-detection-for-service-bus-output-binding-in-azure-functions.html" rel="alternate" type="text/html" title="Duplicate Detection for Service Bus output binding in Azure Functions" /><published>2020-04-01T00:00:00+00:00</published><updated>2020-04-01T00:00:00+00:00</updated><id>https://bryanknox.github.io/2020/04/01/duplicate-detection-for-service-bus-output-binding-in-azure-functions</id><content type="html" xml:base="https://bryanknox.github.io/2020/04/01/duplicate-detection-for-service-bus-output-binding-in-azure-functions.html">&lt;p&gt;Here’s a way to get the Azure Service Bus output binding for your Azure Function working after you’ve enabled Duplicate Detection (or other features) on the Service Bus queue or topic.&lt;/p&gt;

&lt;p&gt;If you haven’t had duplicate detection turned on or haven’t been using some of the other Azure Service Bus features, you might set up the output binding in your Azure Functions so you can send a custom class object to a Service Bus queue or topic. Something like the following.&lt;/p&gt;

&lt;div class=&quot;language-csharp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;FunctionName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MyFunction1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IActionResult&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;HttpTrigger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AuthorizationLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;get&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Route&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HttpRequest&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ServiceBus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%MyQueueName%&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Connection&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;MyServiceBusConnection&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IAsyncCollector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MyItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myOutputQueue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myItem&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MyItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Do stuff.&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// . . .&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Add the item to the queue.&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myOutputQueue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Do more stuff.&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// . . .&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;OkResult&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Notice that the Service Bus out parameter specifies the custom class we want to send to the to the queue or topic. In the example the custom class is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MyItem&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;language-csharp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;IAsyncCollector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MyItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That will work great as long as you don’t have Duplicate Detection (or some of the other features) enabled for the queue or topic.&lt;/p&gt;

&lt;p&gt;See Azure Service Bus Docs: &lt;a href=&quot;https://docs.microsoft.com/en-us/azure/service-bus-messaging/duplicate-detection&quot;&gt;Duplicate detection&lt;/a&gt; and &lt;a href=&quot;https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messages-payloads&quot;&gt;Messages, payloads, and serialization&lt;/a&gt; for more information about Service Bus Duplicate Detection.&lt;/p&gt;

&lt;h3 id=&quot;throws-when-service-bus-has-duplicate-detection-enabled&quot;&gt;Throws When Service Bus has Duplicate Detection Enabled&lt;/h3&gt;
&lt;p&gt;If you enable Duplicate Detection on the queue or topic, your function will throw an
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System.InvalidOperationException&lt;/code&gt; that has a message that starts with:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Message to a partitioned entity with duplicate detection enabled must have either PartitionKey or MessageId set . . .
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;a-solution-to-support-service-bus-duplicate-detection&quot;&gt;A Solution to Support Service Bus Duplicate Detection&lt;/h3&gt;
&lt;p&gt;One way to make it work when duplicate detection is enabled is to output a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Micosoft.Azure.ServiceBus.Message&lt;/code&gt; that contains your custom class, and then set the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MessageId&lt;/code&gt; on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Message&lt;/code&gt; object to be added to the queue or topic.&lt;/p&gt;

&lt;p&gt;This approach will work whether or not duplicate detection is enabled on the queue or topic. You can also use the approach to take advantage of other Azure Service Bus features that require the settings of properties on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Micosoft.Azure.ServiceBus.Message&lt;/code&gt; objects.&lt;/p&gt;

&lt;div class=&quot;language-csharp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;FunctionName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MyFunction2&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IActionResult&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;HttpTrigger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AuthorizationLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;get&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Route&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HttpRequest&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ServiceBus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%MyQueueName%&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Connection&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;MyServiceBusConnection&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IAsyncCollector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myOutputQueue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myItem&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MyItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Do stuff.&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// . . . &lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Add the item to the queue, wrapped in a Message.&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;JsonConvert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;SerializeObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Message&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outputMessage&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Encoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;UTF8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetBytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ContentType&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// Set the MessageId for use in duplicate detection.&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;MessageId&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;$&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TypeId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ItemId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myOutputQueue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outputMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Do more stuff.&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// . . .&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;OkResult&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Notice that we changed the Service Bus out parameter class type to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Micosoft.Azure.ServiceBus.Message&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;language-csharp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;n&quot;&gt;IAsyncCollector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And we wrapped our custom class object (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MyItem&lt;/code&gt; in the example) in a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Message&lt;/code&gt;, and set its &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MessageId&lt;/code&gt; property.&lt;/p&gt;

&lt;div class=&quot;language-csharp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;JsonConvert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;SerializeObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Message&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outputMessage&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Encoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;UTF8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetBytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ContentType&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// Set the MessageId for use in duplicate detection.&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;MessageId&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;$&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TypeId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ItemId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myOutputQueue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AddAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outputMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;under-the-hood-of-the-microsoftazurewebjobsextensionsservicebus&quot;&gt;Under the Hood of the Microsoft.Azure.WebJobs.Extensions.ServiceBus&lt;/h3&gt;
&lt;p&gt;The source code in GitHub for Microsoft.Azure.WebJobs.Extensions.ServiceBus shows how it handles the difference between a custom class and Microsoft.Azure.ServiceBus.Message.&lt;/p&gt;

&lt;p&gt;See &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MessageConverterFactory.cs&lt;/code&gt; at: &lt;a href=&quot;https://github.com/Azure/azure-functions-servicebus-extension/blob/master/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/MessageConverterFactory.cs&quot;&gt;https://github.com/Azure/azure-functions-servicebus-extension/blob/master/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/MessageConverterFactory.cs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserTypeToBrokeredMessageConverter.cs&lt;/code&gt; at: &lt;a href=&quot;https://github.com/Azure/azure-functions-servicebus-extension/blob/master/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/UserTypeToBrokeredMessageConverter.cs&quot;&gt;https://github.com/Azure/azure-functions-servicebus-extension/blob/master/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/UserTypeToBrokeredMessageConverter.cs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a custom class is detected by the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MessageConverterFactory&lt;/code&gt; it calls the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UserTypeToBrokeredMessageConverter&lt;/code&gt; to create a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Micosoft.Azure.ServiceBus.Message&lt;/code&gt; to wrap it. So we can see that under the hood, everything put in a Azure Service Bus queue or topic is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Message&lt;/code&gt;.&lt;/p&gt;</content><author><name>Bryan Knox</name></author><summary type="html">Here’s a way to get the Azure Service Bus output binding for your Azure Function working after you’ve enabled Duplicate Detection (or other features) on the Service Bus queue or topic.</summary></entry></feed>