Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 7-Feb-13 22:13pm
v2
Comments
Richard MacCutchan 8-Feb-13 5:55am    
It's not in C++ 2010 Express either, although it is available in C# 2010 Express.

1 solution

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,
HTML
<configuration>
  <connectionstrings>
    <add name="MyConnString" profidername="System.Data.SqlClient" connectionstring="connString" />
  </connectionstrings>
</configuration>

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"


That will copy the app.config file to yourAppName.exe.config during the build.

Finally, to get the connection string use this:

C++
ConnectionString ^localDb = ConfigurationManager::ConnectionStrings["MyConnectionString"];


Happy hacking.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900