Winforms ConnectionString 和 TeamCity

发布于 2024-11-04 09:52:02 字数 415 浏览 0 评论 0原文


我们正在启动一个新的 WinForms 项目,并决定使用 TeamCity 来创建构建并运行单元和集成测试。该项目涉及数据库。我们有3个数据库(developDB(开发人员在开发时使用=))、testDB(teamcity使用它来运行测试)和productDB(客户端使用它))。 TeamCity 有 3 个构建配置。第一个在提交发生时触发。第二个每晚触发以运行集成测试。第三个是开发人员在我们要发布内容时触发的。因此,我希望 TeamCity 能够根据发生的构建类型来更改连接字符串。另外,我不想将 connectionString 存储在 app.config 中(我不想让客户端知道用户和密码)。有哪些选项可用于执行任务?
预先感谢!
已更新
如果需要的话,我使用 NHibernate 和 FluentNHibernate 连接到数据库。

We are starting a new WinForms project and decided to use TeamCity to create builds and run unit and integration tests. The project deals with database. We have 3 databases (developDB (this is used by developers while developing =) ), testDB (this is used by teamcity to run tests) and productionDB(this is used by client)). TeamCity has 3 buildConfiguration. The first is triggered when commit happens. The second is triggered every night to run integration tests. And the third is triggered by developer when we what to make a release. So I want TeamCity to be able to change connectionString depending on what kind of build happens. Also I don't want to store connectionString in app.config (I don't want client to know the user and password). What options are available to perform the task?
Thanks in advance!
Updated
I use NHibernate and FluentNHibernate to connect to databases if it matters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花想c 2024-11-11 09:52:02

在这种情况下,我将使用 TeamCity 运行 nant 脚本来执行构建。

NAnt 允许您在构建时修改配置文件值(例如连接字符串)。

可以在此博客文章中找到使用 TeamCity/NAnt 部署到不同暂存环境的示例:
http: //thecodedecanter.wordpress.com/2010/03/25/one-click-website-deployment-using-teamcity-nant-git-and-powershell/

正如 @surfen 所建议的,每个环境的连接字符串值应加密以防止凭据以纯文本形式存储。

In this situation, I would use TeamCity to run a nant script to perform the build.

NAnt allows you to modify config file values (such as your connection string) at build time.

An example of using TeamCity/NAnt to deploy to different staging environments can be found at this blog post:
http://thecodedecanter.wordpress.com/2010/03/25/one-click-website-deployment-using-teamcity-nant-git-and-powershell/

As @surfen suggests, the connection string values for each environment should be encrypted to prevent credentials from being stored in plain text.

唯憾梦倾城 2024-11-11 09:52:02

我没有使用过 TeamCity,但我编写了多个在登录过程中(即运行时)动态更改 ConnectionString 的应用程序,而且非常简单。

您没有告诉您如何连接到数据库。既然您提到了 app.config,我想它是 ADO.NET DataSets 或类似技术,它会在您的 Settings.Designer.cs / app.config 中创建一个只读(getter)ConnectionString。

我所做的是在 Settings.cs(而不是 Settings.Designer.cs)中为 ConnectionString 属性创建一个 setter 方法,如下所示:

public void setNorthwindConnectionString(String value) {
    this["NorthwindConnectionString"] = value;
}

然后,我生成的 DataSet 使用此 NorthwindConnectionString 来访问数据。

您可以使用预处理器指令对 ConnectionString 进行条件设置:

#if DEBUG
    Console.WriteLine("Mode=Debug"); 
    Settings.Default.setNorthwindConnectionString("(DebugDBConnectionString)");
#else
    Console.WriteLine("Mode=Release"); 
    Settings.Default.setNorthwindConnectionString("(ReleaseDBConnectionString)");
#endif

您还可以 加密您的连接字符串,并在构建后事件期间复制正确的 app.config。

I have not used TeamCity, but I have written multiple applications with dynamically changing ConnectionStrings during logon process (ie. at runtime), and It's quite simple.

You didn't tell how do you connect to your Database. Since you mention app.config, I suppose it is ADO.NET DataSets or simmilar technology, which creates a read-only(getter) ConnectionString in your Settings.Designer.cs / app.config.

What I did, was to create a setter method in Settings.cs (not Settings.Designer.cs) for the ConnectionString property like this:

public void setNorthwindConnectionString(String value) {
    this["NorthwindConnectionString"] = value;
}

My generated DataSet then uses this NorthwindConnectionString for accessing data.

You can use preprocessor directives for conditional setup of your ConnectionString:

#if DEBUG
    Console.WriteLine("Mode=Debug"); 
    Settings.Default.setNorthwindConnectionString("(DebugDBConnectionString)");
#else
    Console.WriteLine("Mode=Release"); 
    Settings.Default.setNorthwindConnectionString("(ReleaseDBConnectionString)");
#endif

You could also encrypt your connection strings, and copy the right app.config during post build event.

离旧人 2024-11-11 09:52:02

我假设您将使用 msbuild 在 Team city 中构建您的项目。如果是这种情况,那么您可以发送条件编译符号,您可以在其中传递您需要的任何符号。

一旦有了符号,您就可以执行以下操作:

#if DEVBUILD
//.... Your Connection String Code here
#endif

#if INTBUILD
.... Your Connection String Code here
#endif

这就是第一个问题的答案。

看看你问题的第二部分,你不想在哪里存储用户名和用户名? app.config 中的密码,

选项:

  • 尝试集成安全性,如果无法使用选项,它将使用您的域帐户
  • ,尝试将连接字符串保留为注册表项,以便其不明显或环境变量。

I am assuming you would be using msbuild to build your projects in Team city. If that is the case, then you can send the Conditional Compilation Symbol where in you can pass what ever symbols you need.

Once you have the symols, you can do things like:

#if DEVBUILD
//.... Your Connection String Code here
#endif

#if INTBUILD
.... Your Connection String Code here
#endif

That's the answer to your frst question.

Looking at the second part of your question, where in you do not want to store the user name & password in the app.config,

Options:

  • try intergrated security, it will use your domain account
  • if option cannot be used, try keeping your connection string as a Registry Key, so that its not obvious or an Environment variable.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文