Category Archives: Visual Studio 2012

Deploy a database project with TFS Build

When you develop web application you often have this scenario. Some people are testers, they are testing the application in dev all day, and they want always to test latest version. Moreover testers usually fills data into web application, so they want their data to be preserved between various deploy. If you simply clear all data in test database you will end with a lot of furious tester so do not even think to do this.
If a developer needs to change database schema, we need to automate not only the deploy of the web application, but we need also to sync test database with the latest changes. This is necessary so the test site can work with the new version, but old data is preserved for the happiness of the testers.
This is quite simple using TFS and Database project. The situation is this one


When a developer does a check-in, the build server grabs the tip from TFS, then it runs the builds script and deploy the new version of the site in the test web server. At the same time test database gets updated with the latest database schema.

Next we need the ability to automatically deploy changes to a specific database, this task is quite simple and you can find some details here in msdn, but we need to insert this command into the msbuild script. Here is the code:

<Target Name="AfterDropBuild"><Message Text="Deploy of project database" />
<MSBuild Projects="$(SolutionRoot)srcDbEditionNorthwindTestNorthwindTestNorthwindTest.dbproj"
DefaultDataPath=C:Program FilesMicrosoft SQL ServerMSSQL.4MSSQLData;
TargetConnectionString=Data Source=VM2003R2_1SQLTEST%3Buser=sa%3Bpwd=Pa$$w0rd;


Original post from Ricci Gian Maria

Visual Studio 2012 running slow

Three months in and my Visual Studio 2012 is running slow, I’ll even go as far as saying it is freezing up some times, so I loaded up SysInternals Process Monitor and set a filter on Visual Studio and to my complete and utter amazement I found PerfWatson running wild in the system

PerfWatson is designed to drive performance improvements and make Visual Studio faster by automatically reporting back to Microsoft, this sounds great but it is just running crazy on my machine and I need to take it off.

To take it off you need to be in Visual Studio 2012, if you can get it loaded, then go to the Tools/Extensions and Updates sections and you’ll find Visual Studio PerfWatson installed, just uninstall and it will be gone.

Another area to clear out is the WebSiteCache, which Kevin Rintoul wrote about on his blog Slow Visual Studio Performance … Solved!, which can be found at:


If you are using TFS with Visual Studio then another great tip from Nick on his blog post How to fix slow Visual Studio + TFS,

Edit the Visual Studio config file found in C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe.config
and locate the following line:


Right below (above settings, NOT under), insert the following line of code:

<defaultProxy enabled="false" />

Your visual studio should now be more responsive!

Anyone else got any tips to increase the performance of Visual Studio 2012 are most welcome.

SQL71566 when upgrading to VS12

In VS 2012 I receive the following error message (one for each table) when trying to build a database project.

SQL71566: Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlFilegroup cannot not be set on both the Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlTable and the clustered Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlPrimaryKeyConstraint.

For reference here is script associated with this error.

CREATE TABLE [dbo].[OperationsMaster](
[OperationID] [numeric](18, 0) NOT NULL,
[OperationName] [nvarchar](150) NOT NULL,
[OperationTypeID] [numeric](18, 0) NOT NULL,
[OperationID] ASC

In above script in last line on word [PRIMARY] red line appears. When I run the same script in SSMS it executed successfully.

You can get your project to build by enabling the project setting “Enable extended Transact-SQL verification for common objects.”.

Setting up StyleCop

How to get StyleCop working and running in Visual Studio 2012

First download the latest StyleCop from Codeplex, and install.

If you now load up Visual Studio and create a new project, how you’ll find lots of underlined code that need attention

As you can see form above, we now need to start correcting these, most are due to lack of documentation

So once you made the changes things should look better

Now that we have got it running it is time to start to configure StyleCop, if you right click on your project you’ll find StyleCop Settings

One rule which I turn off is SA1126: PrefixCallsCorrectly, just find SA1126 on the Rules tab and uncheck the rule, like this:

You’ll need to rerun StyleCop again and you’ll find that this rule is now ignored.

Setting Up StyleCop MSBuild Integration

Next is to get StyleCop running with all builds for your project, to do this check out Setting Up StyleCop for MSBuild Integration

MSBuild integration will cause the tool to run automatically whenever the code is built, and StyleCop violations will show up alongside compiler errors in the build output.

It is possible to set up the build integration so that StyleCop violations will appear as build warnings, or as build errors if so desired.

Installing MSBuild Files

To enable build integration, first be sure to select the MSBuild option when installing the tool, as shown in the image below:

This will cause the StyleCop binaries and supporting MSBuild targets files to be installed under the {Program Files}\MSBuild\Microsoft\StyleCop folder.

Adding the Import Tag

Once the StyleCop MSBuild files are installed, the next step is to import the StyleCop targets file into your C# projects. This is done by adding an Import tag to each C# project file.

For example, to integrate StyleCop to the project SampleProject, open the project file SampleProject.csproj within your favorite text editor. Scroll down to the bottom of the file and add a new tag to import the Microsoft.StyleCop.targets file. This import tag should be added just below the import of Microsoft.CSharp.targets:

<Project DefaultTargets="Build" xmlns="">

   ...Contents Removed...

  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

  <Import Project="$(ProgramFiles)\MSBuild\StyleCop\v4.7\StyleCop.targets" /> 

   ...Contents Removed...


Save the modified .csproj file. The next time you build this project either within Visual Studio or on the command line, StyleCop will run automatically against all of the C# source files within the project.

Build Warnings Vs Errors

By default, StyleCop violations will show up as build warnings. To turn StyleCop violations into build errors, the flag StyleCopTreatErrorsAsWarnings must be set to false. This flag can be set as an environment variable on the machine, or within the build environment command window. Setting the flag this way will cause StyleCop violations to appear as build errors automatically for all projects where StyleCop build integration is enabled.

Alternately, this flag can be set within the project file for a particular project. Open the .csproj file for your project again, and find the first PropertyGroup section within the file. Add a new tag to set the StyleCopTreatErrorsAsWarnings flag to false. For example:

<Project DefaultTargets="Build" xmlns="">
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

Team Development

The configuration described above will suffice to enable StyleCop build integration on an individual development machine. However, development teams working within a well-defined development environment can set up the build integration in a more global way, so that each developer does not have to manually install StyleCop on his machine.

To do this, copy all of the files from {Program Files}\MSBuild\Microsoft\StyleCop into a custom folder within your build environment, and check all of these files into your source control system. Next, define an environment variable within your development environment which points to the location of the StyleCop targets file. For example:

set StyleCopTargets=%enlistmentroot%\ExternalTools\StyleCop\v4.3\Microsoft.StyleCop.targets

With this configuration in place, it is simply a matter of adding the following import tag to each .csproj file within your development environment:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(StyleCopTargets)" />

StyleCop will automatically run each time this project is built, no matter who is building the project. There is no need for each developer to install StyleCop manually, since the StyleCop binaries are checked directly into your source control system and are centrally integrated into your build environment.

Command Line

If this is not enough for you try it from the command link

msbuild myproj.csproj /p:StyleCopTreatErrorsAsWarnings=false