0

I have just installed VS2017. I am trying to figure out how to use an application config file in a simple CLI program. I created an app.config file, added my app setting like I do in VS2010. This is where I run into problems. I cannot find ConfigurationManager.

In VS2010 I had to add a reference to a .NET assembly and then add "using System.Configuration;" In 2017 when I go to add a reference there is no ".NET assemblies" tab.

I have looked through the "Get tools and features". I suspect I need to install something but I don't know what. All of the MS documentation implies I can just add a "using" directive to get it to work but that hasn't worked for me. (The examples don't compile.)

I'm finding it surprisingly difficult to get up and running. If I'm not supposed to use ConfigurationManager any more then can someone point me in the right direction? If ConfigurationManager is still okay then what have I missed?

jce
  • 133
  • 1
  • 10
  • Project -> Add Reference -> system.configuration – Aaron Feb 09 '18 at 21:05
  • There is nothing in Add Reference. No .Net, no anything – jce Feb 09 '18 at 21:09
  • Yeah sorry man, I completely missed where you said the exact same thing I did. I've had this issue in the past, and as soon as I saw it I figured I knew - didn't finish reading. My bad. Not really sure what's going on. Hopefully someone else can help. – Aaron Feb 09 '18 at 21:15
  • Is this a .NET Core project by any chance? – Craig W. Feb 09 '18 at 21:49
  • It is. That was the first place I found a CLI project. Is that not the correct project type? – jce Feb 09 '18 at 21:52
  • @jce: "Correct" is a relative term. If you meant to create a .NET Core project and you want to run it on more than just Windows then it's correct. If you want to be able to use the tooling and libraries you're used to, then it wasn't the correct choice. When you create your new project select the "Windows Classic Desktop" option in the tree. You'll then see "Console App (.NET Framework)" in the right-hand pane. – Craig W. Feb 09 '18 at 21:54
  • Yup - I see it now. Thank you. Feel free to answer this question and I will mark you as the answer. – jce Feb 09 '18 at 21:57

1 Answers1

1

Because you created your application as a .NET Core application you'll have to change the way you set up and access your configuration settings. Here's another post on SO that explains how to do that.

https://stackoverflow.com/a/46437144/97382

If you want to use the app.config and ConfigurationManager you're used to, you should create a .NET Framework console application. To do so, when you open the New Project dialog you should select the "Windows Classic Desktop" option in the tree. You'll then see "Console App (.NET Framework)" in the right-hand pane.

Craig W.
  • 17,838
  • 6
  • 49
  • 82