Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Monday, 23 July 2012

Visual Studio can work with HTML afterall

Fix Visual Studio’s crappy HTML formatting and automatic addition of id when pasting

Some nice chap called Tim just told me how to solve those two annoying things that Visual Studio does when I'm editing HTML. What two things? You know, the weird thing with the line breaks and opening tags and the one where it insists on adding an ID to every element you paste in the HTML.

Thanks Timmy!






Sunday, 12 June 2011

Visual Studio Breaking on Exceptions for MSTests

At home I don't have ReSharper installed (shock!) and I use MSTests (wtf?!) for some small old projects. Annoyingly VS would break on exceptions when running tests; given that these tests rely on exceptions being thrown it becomes a tad annoying.

Turns out I'm a massive idiot and I was just running the tests with the wrong keyboard shortcut - doh! Here are the shortcuts I was using and the ones I am now using:
  • Ctrl r + Ctrl t => Run tests in current context (debug mode)
  • Ctrl r + t => Run tests in current context
  • Ctrl r + Ctrl a => Run all tests in solution (debug mode)
  • Ctrl r + a => Run all tests in solution

Monday, 16 May 2011

Getting to grips with Git

Git is a world apart from Team Foundaation Server and people seem to be frightened at a first attempts with it, as it can seem complex. Stick with it though and you'll soon see past that and how simple it can be. Git is a distributed source control system, so it allows you to work disconnected from the main repository and still commit. This 'commit' is to your local repository. You should commit often. Once happy that all your tests pass should you push to the remote repository.
  1. clone - get the source code from your remote git repository
  2. Make your changes
  3. commit - commits your changes LOCALLY (not the remote git repository)
  4. push - commits your changes to the REMOTE repository
For me, working disconnected is the number one advantage for Git over TFS. Number 2 is the ability to create branches. Essentially just a seperate work stream you can use for working on seperate features. Once happy, you then merge your branch into the master branch (which is the main repository).
  1. clone - get the source code from the remote git repository
  2. branch branch-name - create a branch branch-name
  3. Make your changes on your branch
  4. commit - commits your changes LOCALLY (not the remote git repository)
  5. push origin branch-name - commits your changes to the REMOTE repository
  6. checkout master - switch to the master branch
  7. merge branch-name - merge the feature branch into the master
  8. commit and push !!!
I'd strongly recommend that you use the git bash until you get to grips with the git comands, then you can make use of the helper tools.
At the moment I'm still working with the bash but I occasionally use TortoiseGit for windows explorer integration and Git Source Control Provider for Visual Studio GUI integration.

Wednesday, 9 June 2010

ASP.Net allowDefinition='MachineToApplication' Error

I've come across this problem a number of times now and it was beginning to annoy me. A few times when building projects on continuous integration servers and today when upgrading my MVC web app to MVC 2 I hit the following error:

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level This error can be caused by a virtual directory not being configured as an application in IIS.

Everytime I failed to figure out what the problem was and instead I had to admit defeat and use a work-around :(

Well the error message is quite helpful for some people getting this error at runtime and tells them how to fix the problem - configure the web apps virtual directory to be an application. However, I'd been stumbling upon this delightful error when compiling projects - not at runtime!

Luckily I had a light bulb moment... the compiler was not referring to my main web.config for the application, but instead was moaning about a web.config within a sub directory of my application (a backup of the project). Deleting the backup sub directory solved my problems!

I got 99 problems but my web.config ain't one!

Thursday, 15 April 2010

The Mappings for the Solution Could Not Be Found!

When trying to bind a disconnected project/solution from Visual SourceSafe in Visual Studio 2008/2010 you may get the following error:

The mappings for the solution could not be found

Fix by changing your source control plugin (Tools -> Options -> Source Control -> Plug-in Selection) to Microsoft Visual SourceSafe.

Wednesday, 31 March 2010

DRY CSS == .LESS

Lots of talk regarding the .LESS (pronounced dot-less) library has prompted me to finally get around to incorporating it within one of my projects - and I'm impressed. .LESS extends on CSS, making your CSS dynamic. It allows you to work with your CSS more easily and without needing to repeat yourself by way of 4 powerful language enhancements:

Variables

Variables specify widely used values in one place such as site colours.

@companyRed: #eeeeee;

h1, h2   { color: @companyRed; } 
#banner  { color: @companyRed; }

Mixins

Collecting sets of rules within a class and allowing other rules to add that class as a property.

.myMixinClass { 
   color: #ffffff; 
   text-align: center; 
   font-weight: bold; 
}

#banner   { .myMixinClass; padding: 30px; }
#footer   { .myMixinClass; padding: 0px; }

Operations

Perform simple math operations between related properties.

@defaultBorder: 1px;
@companyRed: #eeeeee;

#banner {
  color: @companyRed;
  border-left: @defaultBorder;
  border-right: @defaultBorder * 2;
}

#footer { 
  color: (@companyRed + #111) * 1.5;
}

Nested Rules

Avoid long selector names for specifying inheritance, allowing you simply to nest the rules making the CSS a lot more readable.

#header {
  color: red;
  a {
    font-weight: bold;
    text-decoration: none;
  }
}

How does .LESS work?

These language enhancements are parsed and converted to valid CSS on the fly, or can be pre-compiled. It's amazingly easily to start working with and the homepage has all the info you'll probably ever need on .LESS - it really is that simple :)

Performance?

.LESS removes comments by default and has built in support for minification and caching via the optional config values. Although if you are serious about performance I'd suggest using .LESS to compile your .LESS files to .css during the build and leave the caching and compression to IIS.

Gotchas to avoid...

  • Visual Studio 2008 won't know what type of file a .LESS file is, which means it opens it as a plain text file. There is a .LESS Visual Studio Integration Pack (if it asks you to login then click 'login as guest') that I recommend you getting so you have syntax highlighting at least - but I'm afraid intellisense won't be able to help you here.
  • Remember to make sure IIS is setup to forward .LESS resource requests to the ASP.Net engine (if you are working on MVC apps then it will by default).
  • Visual Studio won't set a build action on .LESS files, so remember to set build action to 'content' or the files won't be deployed.
  • As .LESS parses the file I noticed it fell over (didn't process the rest of the CSS file) on this particular CSS hack "border:none!important;" so you may need to rethink your hacks if .LESS doesn't like it.

Monday, 29 March 2010

Visual Studio Team Foundation Server Power Tools

I often forget to comment my check-ins and I'm getting fed up with having a big sign stuck to my monitor saying "Comment Your Check-Ins!". So I've decided to make use of Team Foundation Server Power Tools to enforce a custom check-in policy to ensure everyone checks in comments with their changesets.

Team Foundation Server Power Tools is a set of enhancements, tools and command-line utilities that improve the Team Foundation Server (TFS) user experience.

Other useful features of the add-on include the ability to enforce a 'testing policy' to ensure tests are run before check-in and an alert editor for enabling subscriptions to events (e.g. failed builds) in Team Foundation Server. A very useful add-on indeed :)

Thursday, 25 March 2010

How to Check if ASP.Net Debugger is Attached

Want to know how to check if the ASP.Net debugger is attached in code?

System.Diagnostics.Debugger.IsAttached

Visual Studio Build Actions Property

Each file within a .Net project has a build action property for specifying the build action on the file when a build is executed. Typically the buld action will be one of these:

  • None - The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file.
  • Compile - The file is compiled into the build output. This setting is used for code files.
  • Content - The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.
  • Embedded Resource - This file is embedded in the main project build output as a DLL or executable. It is typically used for resource files.

However, this is not the definitive list as the build action property is extensible.

The default build action property set by Visual Studio is set according to the extension of the file that you add to the solution.

e.g. a Class.cs file would get a build action of compile as it's a code file - simples :)