У меня есть разные строки подключения в appsettings.json и appsettings.Production.json, но после публикации в папке IIS на моем компьютере строки подключения в appsettings.Production.json такие же, как в appsettings.json
Мой Program.cs имеет
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
using (var f = System.IO.File.AppendText(@"C:\temp\log.txt"))
{
f.WriteLine(env.EnvironmentName);//for Debug, it outputs "Production" (without quotes)
}
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false, reloadOnChange: true);
})
.UseStartup<Startup>()
.UseNLog();
appsettings.json
{
//something is omitted
"ConnectionStrings": {
"Northwind": "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=Northwind;Integrated Security=True",
"ApplicationIdentityDbContextConnection": "Server=(localdb)\\mssqllocaldb;Database=OlegTarusovIdentity;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
app.Production.json
{
"ConnectionStrings": {
"Northwind": "\"Data Source=(localdb)\\\\mssqllocaldb;Initial Catalog=Northwind;User Id=sa;Password=Password123",
"ApplicationIdentityDbContextConnection": "Server=(localdb)\\mssqllocaldb;Database=OlegTarusovIdentity;User Id=sa;Password=Password123;MultipleActiveResultSets=true"
}
}
У меня есть CustomProfile.pubxml:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>http://olegtarusov.com</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp2.2</TargetFramework>
<ProjectGuid>917b0f52-135a-4943-991f-12f35fa4a9c6</ProjectGuid>
<SelfContained>false</SelfContained>
<_IsPortable>true</_IsPortable>
<MSDeployServiceURL>localhost</MSDeployServiceURL>
<DeployIisAppPath>OlegTarusov</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>InProc</MSDeployPublishMethod>
<EnableMSDeployBackup>False</EnableMSDeployBackup>
<UserName />
<_SavePWD>False</_SavePWD>
</PropertyGroup>
</Project>
и launchSetting.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50806",
"sslPort": 44348
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Oleg_Tarusov": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
После публикации у меня есть appsettings.Production.json в папке IIS со значениями из appsettings.json:
{
"ConnectionStrings": {
"Northwind": "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=Northwind;Integrated Security=True",
"ApplicationIdentityDbContextConnection": "Server=(localdb)\\mssqllocaldb;Database=OlegTarusovIdentity;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
Я хочуесть appsettings.Production.json как в моем проекте в Visual Studio.Почему мой appsettings.Production.json перекрывается appsetting.json?