Click here to Skip to main content
13,006,319 members (58,978 online)
Rate this:
Please Sign up or sign in to vote.
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 7-Feb-13 19:09pm
Ger Hayden34.5K
Updated 7-Feb-13 22:13pm
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

Rate this: bad
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,
    <add name="MyConnString" profidername="System.Data.SqlClient" connectionstring="connString" />

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170628.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2017
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