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 Hayden27.5K
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 Sascha Lefévre 485
1 Sergey Alexandrovich Kryukov 325
2 Maciej Los 240
3 Abhinav S 164
4 Peter Leow 120
0 Sergey Alexandrovich Kryukov 6,953
1 OriginalGriff 6,311
2 Maciej Los 2,732
3 Peter Leow 2,674
4 Abhinav S 2,562


Advertise | Privacy | Mobile
Web03 | 2.8.150414.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2015
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