April 2008 - Blake Niemyjski

  • Tips & Tricks: Resetting the CodeSmith Sample Templates

    A tip that not a lot of people know is that the samples are not reset during every new release of CodeSmith.  New versions of templates are added to the CodeSmith template directory for the Major and Minor versions. However that is not the case for regular builds (identified via the assembly build number) for example: 4.1.x. Please note that this will also work if you want to reset your templates for the fun of it.

    You might be asking yourself, well why doesn’t CodeSmith automatically update my templates for me. Well there is a pretty good reason behind this. There is no way to know if you modified the current set of templates on your machine. If we were to just overwrite the files with the new templates that contain bug fixes, you could lose a lot of unsaved work.   

    So if you are experiencing a template related bug and you didn’t cleanly install CodeSmith for the very first time on your machine. The chances are your templates are out of date and need to be saved manually and updated following the steps below.

    The following steps below will reset your samples to the version that of CodeSmith that you updated to, or installed to. If the samples still do not show up in CodeSmith Explorer. Then you can find the sample templates located in two zip files: samples.zip and maps.zip, located in Program Files\CodeSmith folder, and you can extract these to the correct folder inside of you’re my documents folder (Documents\CodeSmith\Samples\v4.1\Templates).

    PLEASE CREATE A BACKUP OF ALL YOUR TEMPLATES BEFORE PROCEEDING!!!

    First you will need to exit all CodeSmith related applications (CodeSmith Studio, Visual Studio) and follow the steps below.

    1. Open the Windows Run dialog box by hitting the Windows Key and R. or by going to the Start menu and clicking on run. or start -> run) dialog box and type “cmd” and click the “OK” key.

    2. Next type “cs /resetsamples” into the Command Prompt window and hit enter.
    3. Finally type “y” to confirm that you want to reset your templates and hit enter.

     

    Congratulations your CodeSmith templates have been reset.

  • How-to: Delete dangling files from a Community Server database

    The other day I came across a bug when upgrading my site to Community Server 2008. The Community Server 2008 upgrade tool would throw an exception when trying to move my files into CFS. The exception was result of the upgrade tool trying to pull down post attachments where the Section or Post didn't exist.

    This might not seem like such a bad thing, but it is for two reasons:

    1. You have a file that is taking up database space that isn’t accessible within Community Server.
    2. Community Server appends the SectionID to file name. Since the SectionID is null an exception will be thrown when creating the file name.

    I created the following SQL statement that will delete all cs_PostAttachments where the SectionID and ApplicationType is NULL and the section doesn't exist in the cs_sections table.

    DELETE
        cs_PostAttachments
    FROM
        cs_PostAttachments
    LEFT JOIN
        cs_Sections
    ON
        cs_Sections.SectionID = cs_PostAttachments.SectionID
    WHERE
        cs_PostAttachments.Content NOT LIKE 0x AND
        cs_Sections.SectionID IS NULL AND
        cs_Sections.ApplicationType IS NULL

    -Blake Niemyjski

  • How-to: Reset a CodeSmith license.

    Every once in a while you might run into a licensing problem when using CodeSmith.  This can be when the Visual Studio add-in becomes corrupted, or you encounter some kind of licensing problem and you have problems activating.  You can fix these related problems by resetting the license file and reactivating your copy of CodeSmith. 

    First you will need to exit all CodeSmith related applications (CodeSmith Studio, Visual Studio) and follow the steps below.

    1)    Open the windows run (windows key + r or start -> run) dialog box and type “cmd”

    2)    And type “cs /resetlicense” hit enter and type “y” and hit enter again. This will remove any CodeSmith license files from your computer.
    Your command prompt window should look something like this.

    C:\Users\Administrator>cs /resetlicense
    CodeSmith Console v4.1.3.3349
    Copyright (c) 2002-2008 CodeSmith Tools, LLC.  All rights reserved.
    WARNING: This will reset your license files and you will need to re-register and activate your license.  It will not extend your trial period.
    Press Y to confirm that you would like to reset your license: y
    Reset license complete.

    3)    Next launch CodeSmith studio and try to register your key. You should now see the activation prompt.

windowscoding.com;
Copyright © 2008 Windows Coding
Microsoft and Microsoft logo's are trademarks of Microsoft Corporation.