--- lang: ja-jp breaks: true --- # C# ユーザシークレット の簡単な使用方法。 2024-04-03 ## プロジェクト→右クリック→「ユーザー シークレットの管理」  ## 自動的に開かれる `secrets.json` に Json形式で設定を加える。 ```json= { "VISION_ENDPOINT": "xxxxx", "VISION_KEY": "bbbbb" } ``` ## Program.cs ```csharp= ・・・ using Microsoft.Extensions.Configuration; ・・・ static void Main(string[] args) { Console.WriteLine("Hello, World!"); IConfigurationRoot config = new ConfigurationBuilder() .AddUserSecrets<Program>() .Build(); Console.WriteLine($"{config["VISION_ENDPOINT"]}/{config["VISION_KEY"]}"); } ``` ## csproj ```xml= <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <UserSecretsId>ac34e04a-2643-434d-bf07-829632bbd595</UserSecretsId> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" /> </ItemGroup> </Project> ``` ###### tags: `C#` `secrets.json` `ユーザシークレット`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up