Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet core user-secrets executable mysteriously missing, why?

Installed the most recent (I think) .NET Core, created a .NET Core web project via Visual Studio 2015, and tried to start using user secrets. The CLI claims it is missing (after claiming to have installed it...), as below:

E:\Projects\CodeServer>dotnet --version
1.0.0-preview1-002702

E:\Projects\CodeServer>dotnet restore
 <snip>
log  : Restoring packages for tool 'Microsoft.Extensions.SecretManager.Tools' in E:\Projects\CodeServer\src\CodeServer\project.json...
 <snip>
log  : Restore completed in 2345ms.

NuGet Config files used:
    C:\Users\Work User\AppData\Roaming\NuGet\NuGet.Config
    C:\ProgramData\nuget\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    https://api.nuget.org/v3/index.json
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

E:\Projects\CodeServer>dotnet user-secrets -h
No executable found matching command "dotnet-user-secrets"

E:\Projects\CodeServer>

Also adding the project.json file per request:

{
  "userSecretsId": "<snip>",

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0-rc2-3002702",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Authentication.Google": "1.0.0-rc2-final"
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    },
    "Microsoft.Extensions.SecretManager.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "gcServer": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
like image 281
Fizzbuzz97 Avatar asked Jun 08 '16 22:06

Fizzbuzz97


People also ask

Where are Dotnet user secrets stored?

User Secrets ensures that there is no sensitive data included in the source code. Instead, the user secrets are stored outside of the project folder — inside the user's profile folder in the file system.

What is user secrets in .NET Core?

The user secrets configuration provider registers the appropriate configuration source with the . NET Configuration API. ASP.NET Core web apps created with dotnet new or Visual Studio generate the following code: C# Copy.

How do I use user secrets in dotnet?

By far the easiest way to use User Secrets is via Visual Studio. Right click your entry project and select “Manage User Secrets”. Visual Studio will then work out the rest, installing any packages you require and setting up the secrets file! Easy!


2 Answers

When using any of the tools packages defined in the tools section of your project.json file, you must use them from the same directory that contains the project.json file.

For example, your project.json file is in E:\Projects\CodeServer\src\CodeServer\project.json, but you are trying to execute the command from E:\Projects\CodeServer. If you change to the E:\Projects\CodeServer\src\CodeServer\ directory before attempting to use the tools, the commands will then work.

like image 92
Daniel Grim Avatar answered Oct 16 '22 21:10

Daniel Grim


I have found that the package manager console is sometimes (or all the time for) is unable to use the correct directory (even if it is selected in the default project dropdown). If you first execute the command 'cd src\YourProjectName' and then e.g. 'dotnet user-secrets -h' (for help) you should be able to use the user-secrets tool.

dotnet user-secrets

like image 20
Indregaard Avatar answered Oct 16 '22 20:10

Indregaard