How to get “Manage User Secrets” in a .NET Core console-application?

前端 未结 9 1363
醉梦人生
醉梦人生 2020-12-28 12:07

When I create a new ASP .NET Core Web-Application, I can right-click the project in Visual Studio, and I see a context-menu entry called \"Manage User Secre

相关标签:
9条回答
  • 2020-12-28 12:38

    It appears that they haven't added that (at least to Visual Studio 2015) as an option for Console or DLL apps.

    You can use this as a work around, but do so at your own risk, it will trick Visual Studio into believing that the dll project has Web capabilities as well.

    Assuming Windows OS

    1. Open File Explorer to C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v{Version Number}\DotNet note: 14.0 is VS 2015, 15.0 is 2017 etc

    2. backup the file named Microsoft.DotNet.targets

    3. Add this line to Microsoft.DotNet.targets next to the other ProjectCabability tag

      <ProjectCapability Include="DotNetCoreWeb" />

    4. Save the file, and unload and reload your project / restart visual studio.

    You may also need to delete your .suo file and/or your .vs folder

    You should now see the context menu. It also changes the icon unfortunately. It seems to build just fine, but this is pretty untested so seriously, use at your own risk.

    0 讨论(0)
  • 2020-12-28 12:42

    Additionally to the answers posted here, if you want a link to your own secrets.json file in your project, you can add the following code to an ItemGroup in your project file:

    <None Include="$(AppData)\microsoft\UserSecrets\$(UserSecretsId)\secrets.json" Link="secrets.json" />
    
    0 讨论(0)
  • 2020-12-28 12:43

    Manage User Secrets is available from the context menu of .NET Core Console projects (not just ASP.NET Core projects) since Visual Studio 2019 (verified in version 16.1.3), once you reference the Microsoft.Extensions.Configuration.UserSecrets NuGet.

    0 讨论(0)
提交回复
热议问题