Results 1 to 11 of 11

Thread: Visual Studio 2017 - adding references

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    12
    Rep Power
    9

    Visual Studio 2017 - adding references

    Hi guys
    I am trying to access a connection string created in the web.config file of my project. Using:

    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings["ConnectionStringNameFromWebConfig"].ConnectionString);

    Problem is System.Configuration.ConfigurationManager is not recognised, I've added in 'using System.Configuration' at the top of my page which is greyed out because its not in use - apparently.

    I've done some searching and most of what I found tells me to add the reference to the System.Configuration. This is where I am stuck, first of all I don't have a reference node (which I've read to right click on) but I can right click on the project node and there is an add reference option which I can click however there is nothing available to add. I've got tabs on the left - Projects, Shared Projects, both with a sub tab named solution and then I have browse with a sub tab recent. All are empty, am I meant to point Visual studio at a folder/file? Do I need to install something?

    Im sure this should be an easy answer but I am once again stuck :-/

    If you can help that would be greatly appreciated!

    cheers
    Dan



  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Posts
    1,981
    Rep Power
    154
    Firstly, you should gain an understanding of exactly what namespaces and assemblies are and what it means to import and reference them. Check this out:

    http://jmcilhinney.blogspot.com/2009...importing.html

    Secondly, you should learn how to use the MSDN documentation to determine what assembly and namespace a type is in, if you haven't already. Here's the documentation for that ConfigurationManager class:

    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Note that it states at the top that it is a member of the System.Configuration namespace and it's declared in the System.Configuration.dll assembly. There is not a one-to-one correspondence between namespaces and assemblies. You'll find that there are some members of that namespace declared in other assemblies that are generally referenced by default but that particular assembly is not referenced by default.

    As for the issue, what type of project did you create in the first place? You say that you have a web.config file so it's obviously a web project of some sort. If you don't have a References node in the Solution Explorer then that suggests that you created a web site rather than a web application. I just created a new web site in VS 2017 and this is what my Solution Explorer looked like:

    Web Site.PNG

    Here's what the Solution Explorer looked like after creating a new web application:

    Web Application.PNG

    As you can see, similar but not the same and the latter has a References node while the former does not. There's a reason that web sites are listed under Web -> Previous Versions in the New Project dialogue. You really should avoid creating them and work exclusively with web applications.

    That said, if you have a web site then you should still be able to add the required reference. In my web site project, I right-clicked the project node in the Solution Explorer to open the Reference Manager dialogue and then selected the Assemblies -> Framework node on the left. This listed all the .NET Framework assemblies available and I simply scrolled down to System.Configuration and check it:

    Reference Manager.PNG

    If you did something different along the way then please explain exactly what you did. In future, please explain exactly what you did from the get-go because there are a lot of different options in VS so if you don't tell us which ones you took then we have to guess and guessing means possibly guessing wrong.

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    12
    Rep Power
    9
    Hi
    Thanks very much for the reply, really appreciate this and im reading through the links you've sent me now - just sending in a reply to your post.

    I think for me this is another place for confusion, there are lots of different ways to create a website and as a beginner it is confusing and I can appreciate I haven't explained which option I picked and so this makes it quite difficult to answer - apologies!


    I believe I have created a web application not a website, i added in the web config file myself because my project didnt start with one. However the web application I created originally (which is what this thread is trying to address) looks different to the screenshot you've sent. On creating a new project I am given two options (although I am aware there are other options if I click on the older version tab but I stayed away from those):

    newWebApp.jpg

    So if I select the first one so Core Web Application and then choose Web Application as the template, I see this:
    coreWebApp.jpg

    As you can see there is no references node and there is also no web.config - also if I right click on the project node I still cant see anything in the
    Reference Manager dialogue, its blank. If I choose the Asp.net web application (.net framework) which is the second option I have when creating a new project (as seen in the first screenshot) and then pick web forms as the template. I can then see the references node and it also comes with a web.config file already created so maybe this is where I am going wrong? I have been working with the asp.net core web application. I am happy to switch though as I haven't really got that far.

    cheers
    Dan




  4. #4
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Location
    Norway
    Posts
    434
    Rep Power
    110
    [xcode=c#] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  5. #5
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    12
    Rep Power
    9
    Hi
    Thanks for the additional link, i'll do some reading!

    cheers
    Dan

  6. #6
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Posts
    1,981
    Rep Power
    154
    In an ASP.NET Core application, you can target either .NET Framework or .NET Core, with the latter being the default. If you chose the former then you can still right-click the Dependencies node to add a reference in the usual way. If you choose the latter, I think the only way that you can reference an assembly is by adding the appropriate NuGet package, which you can also do from the Dependencies node.

    As JohnH says, you should stick to ASP.NET applications targeting the .NET Framework for now, unless you specifically want to read up about .NET Core and ASP.NET Core. The newer options probably won't offer you any advantages at this stage and there is less information available and more gotchas.

  7. #7
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    12
    Rep Power
    9
    Thanks guys, i'll look into the .net framework

    cheers
    Dan

  8. #8
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Location
    Norway
    Posts
    434
    Rep Power
    110
    Quote Originally Posted by jmcilhinney View Post
    In an ASP.NET Core application, you can target either .NET Framework or .NET Core
    I think you mean for an ASP.Net Web application you have that choice?
    [xcode=c#] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  9. #9
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    12
    Rep Power
    9
    Yes, im going to try the Asp.net web application (.net framework) option.

  10. #10
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Posts
    1,981
    Rep Power
    154
    Quote Originally Posted by JohnH View Post
    I think you mean for an ASP.Net Web application you have that choice?
    Nope. The ASP.NET Web Application project template can only target the .NET Framework.

    ASP.NET Web Application.PNG

    After selecting the ASP.NET Core Web Application project, you then have to decide between .NET Core and .NET Framework, with the former being the default.

    ASP.NET Core Application.PNG

  11. #11
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Location
    Norway
    Posts
    434
    Rep Power
    110
    I meant the path for web applications was either .Net fw or core when selecting a project type... I didn't know that you can use .Net framework for a "Core" project also.
    [xcode=c#] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

Similar Threads

  1. Question How to establish interbase connection with visual studio community 2017
    By sky06walker in forum Database General Discussion
    Replies: 1
    Last Post: 03-16-2018, 6:17 AM
  2. Using ExtentReports in Visual Studio
    By m_finn in forum Third Party Products
    Replies: 2
    Last Post: 11-20-2017, 12:54 PM
  3. Visual Studio on mac
    By theo3401 in forum C# General Discussion
    Replies: 2
    Last Post: 06-05-2017, 12:26 PM
  4. Question Easiest way to use Github with Visual Studio?
    By Mothil in forum C# General Discussion
    Replies: 0
    Last Post: 02-01-2015, 3:00 PM
  5. flavor of Visual studio for web
    By cPatsDev in forum VS.NET General Discussion
    Replies: 3
    Last Post: 05-18-2013, 9:44 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •