In our product, there are around 400 projects, so in VS 2012, if I want to make a build then it generates code analysis for all 400 projects and I can't manually disable code analysis for each & every project. So I am looking for a mechanism which disables code analysis for entire solution (all projects) rather then applying those settings to individual projects.
-
Are all those projects in one solution? – John Saunders Jan 28 '13 at 11:27
-
Yes, because we also have unit test cases combined with them as well. – Nirav31 Jan 28 '13 at 12:28
-
400 projects in one solution is too many – John Saunders Jan 28 '13 at 12:34
-
Right but our architecture is like that only.... And now we are planning to separate unit test projects so it will be reduced but we need to find the way to disable code analysis for all the projects with some single setting if possible. – Nirav31 Jan 28 '13 at 12:40
-
1For framework 3.5, there is an option in file named "Microsoft.Common.targets" that is RunCodeAnalysis (can set to False) but no such option for framework 4.0 ......... – Nirav31 Jan 28 '13 at 12:52
-
How long does it take to open that solution? – John Saunders Jan 28 '13 at 15:01
-
1About 10 seconds or so, as VS2012 is much faster now. But can you please give some input about disabling code analysis for all projects? – Nirav31 Jan 31 '13 at 06:24
-
1Ten seconds? I don't believe you. In any case, I think the other answers are correct: no way to do this. – John Saunders Jan 31 '13 at 06:35
-
Answer by @ms007 worked well. Alternatively, in some cases most time is taken by `FxCopCmd.exe`. I think it could be possible to replace this file with dummy executable and no real code analysis will be done. – Dzmitry Lahoda Oct 16 '17 at 09:12
-
I would have thought that it could be done with a property sheet that can be loaded by all of the projects. For that type of solution with so many projects I think you should want a common property sheet to easily set properties that apply to all projects. – shawn1874 Aug 30 '23 at 21:45
5 Answers
You can use a little trick to disable the static code analysis for a whole Visual Studio instance as described here. In short:
- Open a
Developer Command Prompt for VS2012
- type
set DevDivCodeAnalysisRunType=Disabled
- type
devenv
to start Visual Studio
Same solution works for Visual Studio 2015 via Developer Command Prompt for VS2015
.

- 939
- 1
- 13
- 34

- 4,661
- 3
- 28
- 31
Not sure there is an easy to do this with VS2012. CodeAnalysis is defined at project level and depends on your build configuration. For example, there is no code analysis in Release.
First, try to create a configuration based on Release.
Another solution (but very bad) may be to run a batch to modify all your project files.
Here is a sample project file (check the element named RunCodeAnalysis) :
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>

- 24,378
- 8
- 83
- 112
-
Thanks for replying...!!! ... But I do know the changes at project level but i want to disable the same at solution level or say for all projects in just one setting or so... – Nirav31 Jan 28 '13 at 12:44
You could write a little console application that reads all the project files out of a solution file and then toggle the Xml Node of each project.
Function to get the project files out of the solution:
public IEnumerable<string> Parse(string solutionFile)
{
if (solutionFile == null)
throw new ArgumentNullException("solutionFile");
if (!File.Exists(solutionFile))
throw new FileNotFoundException("Solution file does not exist", solutionFile);
var projectFiles = new List<string>();
using (var reader = new StreamReader(solutionFile, true))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (line == null)
continue;
line = line.TrimStart();
if (!line.StartsWith("Project(", StringComparison.OrdinalIgnoreCase))
continue;
var projectData = line.Split(',');
var projectFile = projectData[1].Trim().Trim('"');
if (!string.IsNullOrEmpty(Path.GetExtension(projectFile)))
projectFiles.Add(projectFile);
}
}
return projectFiles;
}
And the function to toggle the RunCodeAnalysis Node(s):
public void ToggleCodeAnalysis(string projectFile)
{
if (projectFile == null)
throw new ArgumentNullException("projectFile");
if (!File.Exists(projectFile))
throw new FileNotFoundException("Project file does not exist", projectFile);
var xmlDocument = new XmlDocument();
xmlDocument.Load(projectFile);
var namespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
namespaceManager.AddNamespace("ns", "http://schemas.microsoft.com/developer/msbuild/2003");
var nodes = xmlDocument.SelectNodes("//ns:RunCodeAnalysis", namespaceManager);
if (nodes == null)
return;
var hasChanged = false;
foreach (XmlNode node in nodes)
{
bool value;
if (!Boolean.TryParse(node.InnerText, out value))
continue;
node.InnerText = value ? "false" : "true";
hasChanged = true;
}
if (!hasChanged)
return;
xmlDocument.Save(projectFile);
}

- 4,661
- 3
- 28
- 31
You can use the Package Manager Console window of Nuget to do that.
Create a new text file in the directory "C:\Users{your user}\Documents\WindowsPowerShell" named "NuGet_profile.ps1" and add the following code:
function Disable-CodeAnalysis(){
ForEach ($project in $dte.Solution.Projects) {
Set-CodeAnalysis($project, $false)
}
}
function Enable-CodeAnalysis(){
ForEach ($project in $dte.Solution.Projects) {
Set-CodeAnalysis($project, $true)
}
}
function Set-CodeAnalysis($project, $value){
$projectName = $project.Name
$projectFilePath = $project.FullName
if ([System.String]::IsNullOrWhiteSpace($projectFilePath)){
if($proj.Kind -eq "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}"){
ForEach ($item in $proj.ProjectItems) {
if($item.SubProject -ne $null){
Set-CodeAnalysis($item.SubProject, $value)
}
}
}
continue;
}
$xmlDocument = new-object System.Xml.XmlDocument
$action = "Enable"
if($value -ne $true){
$action = "Disable"
}
Write-Host "$action code analysis for $projectName at $projectFilePath"
$xmlDocument.Load([string]$projectFilePath);
$namespaceManager = new-object System.Xml.XmlNamespaceManager($xmlDocument.NameTable);
$namespaceManager.AddNamespace("ns", "http://schemas.microsoft.com/developer/msbuild/2003");
$nodes = $xmlDocument.SelectNodes("//ns:RunCodeAnalysis", $namespaceManager);
if ($nodes -eq $null){
continue;
}
foreach ($node in $nodes){
$node.InnerText = "$value";
}
$xmlDocument.Save($projectFilePath);
}
Restart Visual Studio. Click the menu "View" | "Other Windows" | "Package Manager Console". Now you can execute the following commands:
> Enable-CodeAnalysis
> Disable-CodeAnalysis

- 3,865
- 1
- 30
- 38
To disable code analysis for particular project :-
- Right click on Project , select Properties.
- On properties page select Code Analysis.
- Uncheck the check box of "Enable Code Analysis on Build".