将app.config添加到VS 2012 desktop Express中的C ++ / CLI项目
如何将app.config添加到VS 2012桌面快报中的C ++ / CLI项目?
这不是我期望的PROJECT>添加新项目。
谷歌帮助不大。
移动它还是不属于Express版本的一部分?
注意:我想我可以手工制作并使用Add Existing Item,但我还是要证明这一点。
How do I add an app.config to a C++/CLI project in VS 2012 desktop express?
Its not where I would expect under PROJECT > ADD NEW ITEM.
Google is not much help.
Has it moved or is it not part of the Express edition?
NOTE: I think I can handcraft one and use Add Existing Item, but I have still to prove this.
它在C ++中不是自动的/ CLI。你必须手动设置它。首先添加新项,实用程序,配置文件。这将在您的解决方案中创建app.config文件。它还应该在编辑器窗口中打开app.config xml文件。不幸的是,没有好的编辑器,但intellisense熟悉这种格式。对于连接字符串,
It''s not automatic in C++/CLI. You have to set it up manually. Start by Add New Item, Utility, Configuration File. That will create the app.config file in your solution. It should also open the app.config xml file in the editor window. Unfortunately, there''s no nice editor, but the intellisense is familiar with the format. For a connection string,
<configuration>
<connectionstrings>
<add name="MyConnString" profidername="System.Data.SqlClient" connectionstring="connString" />
</connectionstrings>
</configuration>
接下来,编辑要使用连接字符串的项目并添加引用到System :: Configuration。 (请记住在文件中添加using命名空间。)然后在项目的属性中,编辑Build Events,Post-Build事件,并添加命令行
Next, edit the project you want to use the connection string in and add a reference to System::Configuration. (Remember to add the using namespace in the file.) Then in your project''s properties, edit the Build Events, Post-Build Event, and add the command line
copy app.config "
(TargetPath).config
(TargetPath).config"
这将在构建期间将app.config文件复制到yourAppName.exe.config。
最后,要获取连接字符串,请使用:
That will copy the app.config file to yourAppName.exe.config during the build.
Finally, to get the connection string use this:
ConnectionString ^localDb = ConfigurationManager::ConnectionStrings["MyConnectionString"];
快乐黑客。
Happy hacking.