EzDevInfo.com

visual-studio-2008 interview questions

Top visual-studio-2008 frequently asked interview questions

Visual Studio - Command to collapse all sections of code?

In Visual Studio (2008) there a command to collapse/expand all the sections of code in a file?


Source: (StackOverflow)

Go to Matching Brace in Visual Studio?

Is there a way in Visual Studio 2008 to go from a closing brace to its opening brace? I've found a fair amount of stuff about highlighting the brace, but nothing about moving the cursor to it.


Source: (StackOverflow)

Advertisements

What does the Visual Studio "Any CPU" target mean?

I have some confusion related to the .NET platform build options in Visual Studio 2008.

What is the "Any CPU" compilation target, and what sort of files does it generate? I examined the output executable of this "Any CPU" build and found that they are (who would not see that coming!) the x86 executables. So, is there any the difference between targeting executable to x86 vs "Any CPU"?

Another thing that I noticed, is that managed C++ projects do not have this platform as an option. Why is that? Does that mean that my suspicion about "Any CPU" executables being plain 32-bit ones is right?


Source: (StackOverflow)

Difference between Rebuild and Clean + Build in Visual Studio 2008

What is the difference between just a Rebuild and doing a Clean + Build in Visual Studio 2008? Is Clean + Build different then doing Clean + Rebuild?


Source: (StackOverflow)

How can I disable ReSharper in Visual Studio and enable it again?

I installed ReSharper, and it works in Visual Studio, but how can disable it?

Whenever I search in the ReSharper menu I can't find a disable option.


Source: (StackOverflow)

Turn off Visual Studio Attach security warning when debugging IIS

When using Visual Studio 2008 or 2010, every time you attach to IIS w3wp.exe you get an Attach Security Warning,

How do you turn this of?

It would be cool to know also, how to keep it attached for linger, as this seems to time out after a while.

Btw: I Added this as a comment to the answer below, the first thing I did was try the msdn article http://msdn.microsoft.com/en-us/library/ms241736.aspx but that doesn't work.


Source: (StackOverflow)

Mercurial .hgignore for Visual Studio 2008 projects

What is a good setup for .hgignore file when working with Visual Studio 2008?

I mostly develop on my own, only occasionly I clone the repository for somebody else to work on it.

I'm thinking about obj folders, .suo, .sln, .user files etc.. Can they just be included or are there file I shouldn't include?

Thanks!

p.s.: at the moment I do the following : ignore all .pdb files and all obj folders.

# regexp syntax.
syntax: glob
*.pdb

syntax: regexp
/obj/

Source: (StackOverflow)

The name 'ConfigurationManager' does not exist in the current context

I am trying to access connectionStrings from the config file. The code is ASP.NET + C#. I have added System.Configuration to reference and also mentioned with using. But still it wouldn't accept the assembly.

I am using VSTS 2008. Any idea what could be the reason?

Another weird thing is the assembly name shown as "System.configuration", a lower case c which is not how names are displayed for other System assemblies.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Utility
{
    public class CommonVariables
    {
        public static String ConnectionString
        {
            get { return ConfigurationManager.ConnectionStrings["EmployeeEntities"].ConnectionString; }
        }  
    }  
}

Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="qbankEntities" connectionString="metadata=res://*/qbankModel.csdl|res://*/qbankModel.ssdl|res://*/qbankModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=localhost;Initial Catalog=qbank;Persist Security Info=True;User ID=**;Password=****;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

Source: (StackOverflow)

Visual Studio setup problem - 'A problem has been encountered while loading the setup components. Canceling setup.'

I've had a serious issue with my Visual Studio 2008 setup. I receive the ever-so-useful error 'A problem has been encountered while loading the setup components. Canceling setup.' whenever I try to uninstall, reinstall or repair Visual Studio 2008 (team system version). If I can't resolve this issue I have no choice but to completely wipe my computer and start again which will take all day long! I've recently received very strange errors when trying to build projects regarding components running out of memory (despite having ~2gb physical memory free at the time) which has rendered my current VS install useless.

Note I installed VS2005 shell version using the vs_setup.msi file in the SQL Server folder after I had installed VS2008, in order to gain access to the SQL Server 2005 Reporting Services designer in Business Intelligence Development Studio (this is inexplicably unavailable in VS2008).

Does anyone have any solutions to this problem?

P.S.: I know this isn't directly related to programming, however I feel this is appropriate to SO as it is directly related to my ability to program at all!

Note: A colleague found a solution to this problem, hopefully this should help others with this problem.


Source: (StackOverflow)

Metadata file '.dll' could not be found

I am working on a WPF, C#3.0 Project and I am getting this error:

Error 1 Metadata file 'WORK=-\Tools\VersionManagementSystem\BusinessLogicLayer\bin\Debug\BusinessLogicLayer.dll' could not be found C:-=WORK=-\Tools\VersionManagementSystem\VersionManagementSystem\CSC VersionManagementSystem

EDIT:

This is how I reference my usercontrols

xmlns:vms="clr-namespace:VersionManagementSystem"
<vms:SignOffProjectListing Margin="5"/>

It happens after every failed build. The only way I can get the solution to compile is to comment out all my user controls and and built the project, then I uncomment the usercontrols and everything is fine.

I have checked build orders, dependencies configurations.

As you can see it seems to have truncated the dll's absolute path... I have read that there is a bug with the length. Is this a possible problem?

It's very annoying and having to comment, build, uncomment, build is becoming extremely tiresome.


Source: (StackOverflow)

Visual Studio C# statement collapsing

When editing really long code blocks (which should definitely be refactored anyway, but that's beyond the scope of this question), I often long for the ability to collapse statement blocks like one can collapse function blocks. That is to say, it would be great if the minus icon appeared on the code outline for everything enclosed in braces. It seems to appear for functions, classes, regions, namespaces, usings, but not for conditional or iterative blocks. It would be fantastic if I could collapse things like ifs, switches, foreaches, that kind of thing!

Googling into that a bit, I discovered that apparently C++ outlining in VS allows this but C# outlining in VS does not. I don't really get why. Even notepad++ will so these collapses if I select the C# formatting, so I don't get why Visual Studio doesn't.

Does anyone know of a VS2008 add-in that will enable this behavior? Or some sort of hidden setting for it?

Edited to add: inserting regions is of course an option and it did already occur to me, but quite frankly, I shouldn't have to wrap things in a region that are already wrapped in braces... if I was going to edit the existing code, I would just refactor it to have better separation of concern anyway. ("wrapping" with new methods instead of regions ;)


Source: (StackOverflow)

In release mode, code behavior is not as expected

The following code generates different results under debug mode and release mode (using Visual Studio 2008):

int _tmain(int argc, _TCHAR* argv[])
{

    for( int i = 0; i < 17; i++ ) 
    { 
        int result = i * 16;

        if( result > 255 )
        {
            result = 255;
        }

        printf("i:%2d, result = %3d\n", i, result) ; 
    } 

    return 0;
}

The output of debug mode, which is as expected:

i: 0, result =   0
i: 1, result =  16
(...)
i:14, result = 224
i:15, result = 240
i:16, result = 255

The output of release mode, where i:15 result is not correct:

i: 0, result =   0
i: 1, result =  16
(...)
i:14, result = 224
i:15, result = 255
i:16, result = 255

By choosing "Optimization -> Not to optimize" in Visual Studio under release mode, the output result will be correct. However I would like to know why the optimization process could lead to erroneous output.


Update:

As suggested by Mohit JainBy, prints by:

printf("i:%2d, result = %3d, i*16=%d\n", i, result, i*16) ;

The release mode output is correct:

i: 0, result =   0, i*16=0
i: 1, result =  16, i*16=16
(...)
i:14, result = 224, i*16=224
i:15, result = 240, i*16=240
i:16, result = 255, i*16=256

Source: (StackOverflow)

C# - Selectively suppress custom Obsolete warnings

I'm using the Obsolete attribute (as just suggested by fellow programmers) to show a warning if a certain method is used.

Is there a way to suppress the warning similar to CodeAnalysis' SuppressMessage at points where the use is justified?

Thank you!

EDIT

This is for [Obsolete("Some message")] as I need to include some details about the warning. However, #pragma warning disable 612 doesn't work anymore once I add the message to the naked [Obsolete] attribute...

EDIT 2

Found the right warning number - It is 618 if you have a message following the obsolete attribute.

So to do what I want to do:

#pragma warning disable 618

and then after the call

#pragma warning restore 618

Thanks to Jared Par and Jon Skeet for pointing me in the right direction!


Source: (StackOverflow)

Visual Studio Post Build Event - Copy to Relative Directory Location

On a successful build, I wish to copy the contents of the output directory to a different location under the same "base" folder. This parent folder is a relative part and can vary based on Source Control settings.

I have listed a few of the Macro values available to me ...

$(SolutionDir) = D:\GlobalDir\Version\AppName\Solution1\build

$(ProjectDir) = D:\GlobalDir\Version\AppName\Solution1\Version\ProjectA\

I want to copy the Output Dir contents to the following folder :

D:\GlobalDir\Version\AppName\Solution2\Project\Dependency

The base location "D:\GlobalDir\Version\AppName" needs to be fetched from one of the above macros. However, none of the macro values list only the parent location.

How do I extract only the base location for the post build copy command ?


Source: (StackOverflow)

How do I run NUnit in debug mode from Visual Studio?

I've recently been building a test framework for a bit of C# I've been working on. I have NUnit set up and a new project within my workspace to test the component. All works well if I load up my unit tests from Nunit (v2.4), but I've got to the point where it would be really useful to run in debug mode and set some break points.

I've tried the suggestions from several guides which all suggest changing the 'Debug' properties of the test project:

Start external program: C:\Program Files\NUnit 2.4.8\bin\nunit-console.exe
Command line arguments: /assembly: <full-path-to-solution>\TestDSP\bin\Debug\TestDSP.dll

I'm using the console version there, but have tried the calling the GUI as well. Both give me the same error when I try and start debugging:

Cannot start test project 'TestDSP' because the project does not contain any tests.

Is this because I normally load \DSP.nunit into the Nunit GUI and that's where the tests are held?

I'm beginning to think the problem may be that VS wants to run it's own test framework and that's why it's failing to find the NUnit tests?

Edit: To those asking about test fixtures, one of my .cs files in the TestDSP project looks roughly like this:

namespace Some.TestNamespace
{
    // Testing framework includes
    using NUnit.Framework;

    [TestFixture]
    public class FirFilterTest
    {
        [Test]
        public void Test01_ConstructorTest()
        {
            ...some tests...
        }
    }
}

...I'm pretty new to C# and the NUnit test framework so it's entirely possible I've missed some crucial bit of information ;-)

Final Solution: The big problem was the project I'd used. If you pick Other Languages -> Visual C# -> Test -> Test Project ...when you're choosing the project type, Visual Studio will try and use it's own testing framework as far as I can tell. You should pick a normal C# class library project instead and then the instructions in my selected answer will work.


Source: (StackOverflow)