简体   繁体   English

Visual Studio Web Deploy在发布时不会修改连接字符串

[英]Visual Studio Web Deploy does not modify Connection Strings at Publish time

I have a WebApp ASP.Net Core 2.1 contains multiple database connection strings, which are specified into an appsettings.json configuration file. 我有一个WebApp ASP.Net Core 2.1包含多个数据库连接字符串,这些字符串在appsettings.json配置文件中指定。 When developing locally, they are set to point a Local Database for debugging purposes. 在本地进行开发时,它们被设置为指向本地数据库以进行调试。

At Publish Time, those connection strings were modified by the Visual Studio Web Deploy Publisher , in the settings panel as per screenshot below. 在发布时,这些连接字符串由Visual Studio Web Deploy Publisher修改 ,位于设置面板中,如下图所示。 But, for a few days, those connection strings are no more modified automatically by the publisher , despite check-boxes "Use this connection string at run time" are checked. 但是,几天 ,尽管选中了“在运行时使用此连接字符串”复选框,但发布者不再自动修改这些连接字符串

This is super painful : the app crashes right after publishing (cannot connect to databases) and I have to go over FTP to change manually those connection strings. 这非常痛苦:应用程序在发布后立即崩溃(无法连接到数据库),我必须通过FTP手动更改那些连接字符串。

Context of the bug 错误的上下文

In the past days, I created a shared appsetting.json file across multiple projects. 在过去的几天中,我跨多个项目创建了一个共享的 appsetting.json文件。 This shared setting file is referenced as a linked file on every project. 在每个项目中,此共享设置文件都被称为链接文件。 On my Web App project, I changed the startup class to embed this additional configuration file into the ConfigurationRoot. 在我的Web App项目中,我更改了启动类,以将该附加配置文件嵌入到ConfigurationRoot中。 Using the default Startup constructor was not embedding this additional setting file. 使用默认的Startup构造函数未嵌入此附加设置文件。

public class Startup
{           
    //public Startup(IConfiguration configuration)  //Default Startup constructor which DOES not take into account the  sharedappsettings.json configuration file
    //{
    //    Configuration = configuration;
    //}

    public Startup(IHostingEnvironment env)
    {
        var contentRoot = env.ContentRootPath;

            var builder = new ConfigurationBuilder()
                .SetBasePath(contentRoot)
                .AddJsonFile("appSettings.json")
                .AddJsonFile("sharedappSettings.json");
            Configuration = builder.Build();
    }

Questions 问题

  • Why the publisher not modify anymore the various connection strings, despite the interface shows that it shall do it? 尽管界面显示它应该这样做,但为什么发布者仍不再修改各种连接字符串?
  • How can I override this behavior, and change those connection strings at publish time, outside of the Web Deploy interface if not possible otherwise? 如果没有其他方法,如何覆盖此行为,并在发布时更改Web Deploy界面之外的那些连接字符串?

Visual Studio Web Deploy Screenshot Visual Studio Web部署屏幕截图

Visual Studio Web部署发布者

I would look at config transforms: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-2.2 我会看一下配置转换: https : //docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-2.2

This allows you to make config changes which extend beyond connection strings for all of the environments in your pipeline. 这使您可以进行配置更改,这些更改超出了管道中所有环境的连接字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM