dotnet thoughts 

a dotnet developer's technical blog

How to execute a macro after Build is completed

Recently I started using VS Professional edition, which doesn’t have an inbuilt Source code analysis option. And I have to run the Source code analysis after each build. And today I found a solution for the same using environmental macros.
Open the Macros IDE, from Tools > Macros > Macros IDE. This will launch Visual Studio macro editor.
Double click on the MyMacros project, from the Project explorer.
Open the EnvironmentEvents class. This class contains various system generated code, add the following code in below the region.

Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, _
                                        ByVal Action As EnvDTE.vsBuildAction) _
                                        Handles BuildEvents.OnBuildDone
        If Action = vsBuildAction.vsBuildActionClean Then
            Exit Sub
        End If
        If MsgBox("Run Source Code Analysis?", _
                  MsgBoxStyle.YesNo + MsgBoxStyle.Question, "FxCop - Confirm") = _
                  MsgBoxResult.Yes Then
            DTE.ExecuteCommand("Tools.ExternalCommand6")
        End If
    End Sub

This method will be executed once the Build is finished. As I integrated FxCop with my Visual Studio as my external tools, it will execute the External Command 6. It will display a confirmation message, after completing the Build, and if yes press, it will execute the FxCop.

Happy Coding :)

Windows 7 SDK Installation success or error status: 1603

Today my team lead asked me to install FxCop 10 for static code analysis(which is available as part of Windows 7 SDK.) in our projects. As I am using Visual Studio Professional edition, the inbuilt option for Static code analysis is not available. I downloaded the Windows 7 SDK ISO from http://www.microsoft.com/download/en/details.aspx?id=8442 link. And I am able to start the installation. After some time, I got a wiered error like the following -

Windows 7 SDK - Installation Error

Windows 7 SDK - Installation Error

After checking the log file I found a line like this. Installation success or error status: 1603. I searched for this particular error and it was a generic error, sometimes it was related to low disk space. I tried the installation serveral times and everytime I got the same error. Then I modified the installation options, I un-checked all the VC++ related options; which is not required for me. And its worked :) Later I found some problem with the VC++ compiler options and Microsoft has released a patch for it. And you can down load it from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=4422

Happy Coding :)

How to integrate FxCop to Visual Studio 2010 Professional

VS 2010 Professional doesn’t support Static code analysis. Here is a simple way to integrate FxCop to Visual Studio. (It was also using External tools option from Visual Studio tools menu.)

  1. In the Title text box, type FxCop.
  2. Integrate FxCop to Visual Studio

    Integrate FxCop to Visual Studio

    .

  3. To set the value of the Command text box, browse to the location where FxCop is installed, and select FxCopCmd.exe.
  4. In the arguments text box, type the following command : /c /f:$(TargetPath) /d:$(BinDir) – More information : FxCop command line reference
  5. Set the Initial Directory to the location where FxCopCmd should start.
  6. Select the Use Output window check box. – This will display the output of FxCopcmd.exe to output window, and you can double click and navigate to the line number.
  7. FxCop - Source code analysis results in VS output window

    FxCop - Source code analysis results in VS output window

  8. Click OK.

Happy static code analysis :)

.Net Framework Initialization Error – Unable to find a version of the runtime to run this application

I got this error yesterday while running FxCop application from Microsoft. I think the problem was because of the .Net framework installed on my machine, I have only .Net 4.0 installed and no other versions of .Net. And I think FxCop was expecting .Net 2.0 in the system.

.Net Framework Initialization Error – Unable to find a version of the runtime to run this application

.Net Framework Initialization Error – Unable to find a version of the runtime to run this application

After few searches I found the resolution for this issue. You can add supportedRuntime tag to the application config (It will be like ApplicationName.exe.config in the same folder where application installed.) file, under startup tag, and set the attribute of the supportedRuntime as the version of the .Net Framework installed in the system.

<startup>
  <supportedRuntime version="v4.0.30319" />
</startup>