Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 7-Feb-13 20:09pm
Ger Hayden25.8K
Edited 7-Feb-13 23:13pm
v2
Comments
Richard MacCutchan at 8-Feb-13 5:55am
   
It's not in C++ 2010 Express either, although it is available in C# 2010 Express.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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>
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:
 
ConnectionString ^localDb = ConfigurationManager::ConnectionStrings["MyConnectionString"];
 
Happy hacking.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 359
1 Maciej Los 290
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 185
4 PIEBALDconsult 149
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100