global tool - appsettings.json
See original GitHub issueSteps to reproduce
I am developing a global tool, and the first thing it does is in it’s entry point, is load some configuration from a local appsettings.json
file.
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddCommandLine(args) .Build();
My csproj
looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>dotnet-foo</AssemblyName>
<RuntimeIdentifiers>win-x64;win-x86;osx.10.10-x64;osx.10.11-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64</RuntimeIdentifiers>
<PackageType>DotnetCliTool</PackageType>
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
</PropertyGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
I dotnet pack
the tool and can see the appsettings.json
file included along side the .dll
inside the nuget package.
I upload the nuget
package to an internal feed.
I install the tool somewhere using: dotnet tool install dotnet-foo --tool-path ./my-tool
--add-source “https://packages.foo.com/nuget/App/”
The tool installs successfully.
However when I run the tool, it crashes as it cannot find the appsettings.json
file.
Looking in the tool install directory, there is no appsettings.json
file.
Expected behaviour
Tool can be distributed with content files such as appsettings.json
Actual behavior
Tool is installed missing content files such as appsettings.json.
Environment data
dotnet --info
output:
Version: 2.1.401 Commit: 91b1c13032
Runtime Environment: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.401\
Host (useful for support): Version: 2.1.3 Commit: 124038c13e
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:13 (1 by maintainers)
Top GitHub Comments
@dazinator in the program you explicitly state the
BasePath
is the current directory. And once you install it on your path theCurrentDirectory
depends on what is your shell at. CLI does carry the appsettings.json file but it is stored in the same directory of dlls. To access it you need to read it like the followingIt looks like you installed it using --tool-path not -g for global.