Posts Tagged ‘visual studio’
March 2nd, 2013
Visual studio contains snippets. These are “shortcuts” for writing various code. Try writing for in the editor and text is typed in for you and you get placeholders for faster code writing.
One can write code like this oneself. It is quite easy. Just go to menu->Tools->Code snippets manager and work from there; copy, paste and rewrite to your will. (The location field is the folder of the very snippets.)
Here is an example of mine.
I know that some people swear that #region is the devil’s own child but there are other, let’s call us them for pragmatists for now that say that if it fits it fits. The standard snippet outcome for a region is
1 2 3 4 5
| #region // Name of region.
//code
//code
//code
#endregion |
but I prefer
1 2 3 4 5
| #region // Name of region.
//code
//code
//code
#endregion // Name of region. |
So I just copypasted the existing snippet to this; which you can import through above mentioned menu.<?xml version=”1.0″ encoding=”utf-8″ ?>
<CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”>
<CodeSnippet Format=”1.0.0″>
<Header>
<Title>#region</Title>
<Shortcut>region</Shortcut>
<Description>Code snippet for #region</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<ToolTip>Region name</ToolTip>
<Default>MyRegion</Default>
</Literal>
</Declarations>
<Code Language=”csharp”><![CDATA[#region $name$
$selected$ $end$
#endregion // $name$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
February 27th, 2013
Short story: http://msdn.microsoft.com/en-us/library/ms182470.aspx
I still miss a shortcut for “Debug the last unit test”. There is “Repeat the last run” but that runs and doesn’t debug. Strange since that is what I during times use the most. I have resorted to marking the test and the alt-s-d-enter.
Also: Resharper interferes with the shortcuts but that is more a facet of life I think.
October 2nd, 2011
There is no problem versioning a project - just edit the AssemblyInfo.cs file. But how does one update all assemblies in a solution without having to update this file for every project?
Create a AssemblyInfo.shared.cs file in any project and fill it with the versioning parts. Then link this file from all the other projects through the dropdown by the add button in the add existing file dialogue. One cannot create a file directly in the Properties folder so add it in the root of the project and then move it to the Properties folder.

Semi hidden Add as link.
VB.Net
The trick to do it is VB.Net (as of Visual studio 2012) is to update the vbproj file to something like
1 2 3
| <Compile Include="..\MyOtherProject\My Project\AssemblyInfo.shared.vb">
<Link>My Project\AssemblyInfo.shared.vb</Link>
</Compile> |
Above Include… is where the file is linked form and Link… is where it shows up in the target project. Presumably the easiest way to do it is to link the shared file into the root of the target project and then move it through editing the project. As with C# there is no way to directly link a file into My Project folder but one has to first link it to some other place in the target project and them move it through this hack.
(sorry for the > and < but it’s late and I really want to get the stuff into production, not update a blog)
Team city
I also cannot get it to work together with Team city. Moving the version to a file with a different name makes Teamcity update AssemblyInfo.cs and then we get 2 references to the same [assembly: AssemblyVersion("1.0.0.0")]. Maybe this on Stackoverflow would save my day but I haven’t had the time to delve into it.
I have another solution idea and that is to set AssemblyInfo.cs as shared and then create a unique AssemblyInfo.project.cs for each project. Have not had time for this either.
Honor those who should.
September 5th, 2011
I just found out that Dpack, possibly the most important gratis tool for Visual studio there is going open source. Now I wish for time to make this super product even better!
June 25th, 2011
In Visual studio 2010 I have a solution with some projects and a unit test project. Besides the usual configurations Debug and Release I also have Debug_Test. One sunny day when compiling the project …
… I got a dialogue with
Duplicate Detected Loading Add from test.dll
In attempting to load Add form test\bin\debug\test.dll, it was determined that a test with the same id name Add in test\bin\debug_test\test.dll already exists in the catalog.
If you retry, Add from test\bin\debug\test.dll will have its id replaced with a new one.
when I tried to compile my solution with Debug_Test active. (or if it was the other way around)
When I pressed Retry I got
Error loading C:\Test\bin\Debug\Test.dll: The test ‘Add’ from ‘c:\test\bin\debug\test.dll’ that is loading has the same TestId {2704e894-0db5-60e4-53Ed-61c7e6951c9f} as the test ‘Add’ already loaded from ‘c:\test\bin\debug_test\test.dll’.
in the output console.
What was happening?
Check out the emphasis (I created). There are two compile configurations that clash.
I want Debug to compile the whole solution with the debug flag set (to know that everything compiles as it should). Then I have a Debug_Test configuration that only compiles the parts of the solution that are needed for my automatic tests. In the inner machinery of Visual studio 2010 there is something that tracks test methods and it looks like it regards Add from Debug configuration and Add from Debug_Test configuration as two different tests, albeit with the same name.
In reality they are the same unit test method code.
The whys and the hows are beyond my scope but I found a work around.
Go to the other configuration (i.e. Debug) and clean the output. Then go back to the one you want to work with (i.e. Debug_Test) and continue as usual.
One could possibly have created Debug_Test without checking Create new project configurations to avoid this too. If anyone knows, please comment.
May 3rd, 2011
This setting has been around a long time but it seems to still elude users.
There is a way to have the document you have open in Visual studio to also be tracked and highlighted in the Solution explorer window.
Menu->Tools->Options->

Checkbox: Track active item in Solution explorer
March 25th, 2011
Since I have been having problems with reaching my company’s TFS server from home I started with SVN. One could say I use SVN as an offline SCM.
#1: Don’t use Visual studio for both version managers in the same solution.
Visual studio takes for granted one solution is against one SCM. Swapping TFS and SVN messes everything up.
#1.1: Use Visualstudio with TFS and SVN with explorer.
I don’t think there is a TFS tool for explorer so the other way around is not possible. This means I checkin TFS from Visual studio and commit SVN from explorer.
#2: Stuctural changes take time. And possibly ruins the history.
I don’t try to keep the SCMs in sync but instead have the TFS as main repository. I make sure folder moves etc. are done properly in TFS and then just reset (get everything – commit whatever it looks like) in SVN.
With these caveats sorted out it works nice.
March 22nd, 2011
Due to some reason unknown to man there is in Windows the idea of every window to have a title bar, unusable for anything but dragging and double clicking and holding approximately four buttons. Chrome and Opera have reused the space for tabs, well done!
Visual studio has its own solution. Press shift-alt-enter (or somewhere on the menu) and the application maximizes itself to get rid of caption bar and borders. Unfortunately the menu is still visible (it should be able to set it to auto hide) . Then remove the tool bars and set the tool windows to auto hide; almost everything is now the editor.
Now shift back to the space wasting layout (shift-alt-enter) and the old setting is back. So not only do we get more working space, we get a fast layout switch too the same way it switches layout when and when not debugging.
Also applicable for Sqlserver management studio.

Viusal studion x 2
July 13th, 2009
Visual studio database edition is part of the “normal” Visual studio. One cannot be totally sure of this since Microsofts licences are as comprehensible as scientology.
I made two tries at it before I got it to work. Then it failed me anyway, but that is another posting.
The way to think is to think about the database as source code. You make changes, compare them to the checked in/commited code and let the machine do its magic merge and check in the result.
Note: it does not handle databases with data in them but truncates everything. My presently preferred solution is here.