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

Saturday, December 19, 2015

Group Regex Replace in Visual Studio

Wow, I cannot believe that I did not know about this until now!

We all know that you can use regular expressions to search for things in a document, and we all know that you can replace those matches, but did you know that you can use group matches from your regex in the replace value? Because you can, and it is amazingly useful!

Example: Your class has properties with one attribute containing a value, and you want to add another attribute with the same value.

Find: \[Description\("(\w+)"\)\]

public class MyClass
{
    [Description("A"), DisplayName("A")]
    public string A { get; set; }
 
    [Description("B")]
    public string B { get; set; }
 
    [Description("C")]
    public string C { get; set; }
}

Replace: [Description("$1"), DisplayName("$1")

public class MyClass
{
    [Description("A"), DisplayName("A")]
    public string A { get; set; }
 
    [Description("B"), DisplayName("B")]
    public string B { get; set; }
 
    [Description("C"), DisplayName("C")]
    public string C { get; set; }
}

Enjoy,
Tom

Thursday, September 5, 2013

How to Start Using TypeScript Today!

Here are several tips to get you started using TypeScript (currently on 0.9.1.1) today!

Compile on Save

For fast development you MUST compile your TypeScript files on save. While this is not built into the current pre 1.0 release of TypeScript, it is still very easy to enable. There is a very simple article on CodePlex that provides you the exact XML configuration to add to your Project file to compile on save.

Compile-On-Save

Here are some the simple steps to compile on save:

  1. Right click on your project in Solution Explorer and unload it.
  2. Rick click on your project file and open it for editing.
  3. Copy and paste the PropertyGroup and Import nodes from the link above.
  4. Save and close the project file.
  5. Right click and reload the project in solution explorer.
  6. Open the TypeScript Options
    • Tools -> Options -> Text Editor -> TypeScript -> Project -> General
  7. Check "Automatically compile TYpeScript files which are part of a project"
  8. Close the options menu, you are almost done!
  9. Open your TypeScript (.ts) file and save it...boom, it compiled on save. :)

Make Generated Files Dependent

Whenever you compile a TypeScript file it will generate a JavaScript file for you. However, as of .9, that JavaScript file will not be automatically included in your project. First, you should include those generated files in your project. Second, you should modify the project file to mark those generated fiels as being dependent upon their related TypeScript (.ts) file. This will ensure that no one accidentally modifies those files, and it will ensure that TFS automatically checks them out for edit before being regenerated.

<TypeScriptCompile Include="Scripts\jqueryExtensions.ts" />
<Content Include="Scripts\jqueryExtensions.js">
  <DependentUpon>jqueryExtensions.ts</DependentUpon>
</Content>

Here are some the simple steps to compile on save:

  1. Right click on your project in Solution Explorer and unload it.
  2. Open your project file in a text editor.
  3. Add a dependent node under the JavaScript file (see above for an example).
  4. Right click and reload the project in solution explorer.

Use a Master Definition File

Your TypeScript files require reference tags to include information about other TypeScript files. One of my favorite features of TypeScript is that the community builds definition files for other frameworks. However including multiple references in each file is a lot of work, and a bad idea in general.

I strongly suggest keeping one master definition that references all of your other definition files, and then your code files need only reference that one file inherit information regarding all of your code and dependencies.

Master Definition File

/// <reference path="jquery.d.ts" />
/// <reference path="jqueryui.d.ts" />
 
interface JQuery {
    alertOnClick(): JQuery;
}
 
interface JQueryStatic {
    stringFormat(format: string, ...args: Array<any>): string;
}

Normal Code File

/// <reference path="../Definitions/typeScriptDemo.d.ts" />
 
(function ($: JQueryStatic) {
 
    $.stringFormat = stringFormat;
 
    function stringFormat(format: string, ...args: Array<any>): string {
        return format.replace(/{(\d+)}/g, replaceFormat);
 
        function replaceFormat(match, index) {
            return typeof args[index] != 'undefined'
                ? args[index]
                : match;
        }
    }
 
})(jQuery);

Next week I'll talk about how to get your TypeScript compiling on Team Foundation Server.

Shout it

Enjoy,
Tom

Wednesday, November 28, 2012

XNA and Visual Studio 2012 on Windows 8

Microsoft does not always make it easy to use their latest toys.

The Good
I recently rebuilt my computer and, wanting to stay on the forefront of technology, I of course installed Windows 8 and Visual Studio 2012. Both products come with a series of pros and cons, but the quick boot up times of Windows 8 and the parallel builds of Visual Studio 2012 make them both winners in my book.

The Bad
That being said, the first project that I wanted to work on after rebuilding my machine was a small XNA game that I have been writing for a while now. Unfortunately that XNA has been unofficially retired, and Microsoft is not making it easy for people to continue using their product.

And The Ugly
To use XNA on Windows 8 you must first download and install Games for Windows LIVE Redistributable. Then you must install XNA Studio into Visual Studio 2010 and manually copy the installed assemblies to Visual Studio 2012.

Here are the details:

I hope that helps,
Tom

Friday, October 26, 2012

xUnit Visual Studio Integration

Good news, everyone! It is actually very easy to get xUnit completely integrated with Visual Studio. You only need to install two plugins...

VS2010 - xUnit Test Runner Extension

This will support running tests with a Visual Studio test project.
This includes all of the VS features, such as code coverage!

https://github.com/quetzalcoatl/xvsr10/downloads

ReSharper - xUnit Contrib Plugin

This will allow ReSharper to detect and run xUnit tests.

http://xunitcontrib.codeplex.com/releases/view/92101
(If you are still running Resharper 6, then you will need the latest: v6.1.1)

Team Build (TFS) Integration

Integrating with xUnit your Team Foundation Server is a very tricky proposition, but it can be done. That, however, is a (rather long) blog post for another day!

Shout it

Enjoy,
Tom

Real Time Web Analytics