cleanup, add launch settings for console

This commit is contained in:
Ryan Peters 2023-03-18 23:00:14 -04:00
parent 5cc7965400
commit 29c26ae194
8 changed files with 45 additions and 16 deletions

View File

@ -1,12 +1,18 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Net.Http.Json;
using WeatherDashboard;
var builder = Host.CreateDefaultBuilder(args);
builder.ConfigureAppConfiguration(config =>
builder.ConfigureAppConfiguration((context, config) =>
{
config.AddJsonFile("settings.json");
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
config.AddEnvironmentVariables();
config.AddJsonFile("appsettings.json");
config.AddJsonFile($"appsettings.{environment}.json", true);
});
builder.ConfigureServices(services =>
@ -22,3 +28,6 @@ var httpClientFactory = app.Services.GetService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient();
var apiUrl = configuration["ApiUrl"];
var weatherSet = await httpClient.GetFromJsonAsync<WeatherSet>(apiUrl);
Console.WriteLine(weatherSet.Current.ConditionName);

View File

@ -0,0 +1,10 @@
{
"profiles": {
"console": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -7,6 +7,20 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.Development.json" />
<None Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
@ -17,4 +31,11 @@
<ProjectReference Include="..\WeatherDashboard\WeatherDashboard.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Properties\launchSettings.json">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,3 @@
{
"ApiUrl": "http://localhost:5123/api"
}

View File

@ -16,13 +16,6 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -6,13 +6,6 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Models\**" />
<Content Remove="Models\**" />
<EmbeddedResource Remove="Models\**" />
<None Remove="Models\**" />
</ItemGroup>
<ItemGroup>
<_WebToolingArtifacts Remove="Properties\PublishProfiles\Release.pubxml" />
</ItemGroup>