<?xml version="1.0"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	
	<UsingTask TaskName="ICSharpCode.Build.Tasks.FxCop"
	           AssemblyFile="$(SharpDevelopBinPath)\ICSharpCode.Build.Tasks.dll"/>
	
	<PropertyGroup>
		<!-- Prevent problems with VSTS code analysis -->
		<SharpDevelopRunCodeAnalysis>$(RunCodeAnalysis)</SharpDevelopRunCodeAnalysis>
		<RunCodeAnalysis>False</RunCodeAnalysis>
		
		<!-- Define compilation symbols -->
		<DefineConstants      Condition="'$(SharpDevelopRunCodeAnalysis)'=='true' and '$(Language)'!='VB' ">$(DefineConstants);CODE_ANALYSIS</DefineConstants>
		<FinalDefineConstants Condition="'$(SharpDevelopRunCodeAnalysis)'=='true' and '$(Language)'=='VB' ">$(FinalDefineConstants),CODE_ANALYSIS=1</FinalDefineConstants>
		
		<!-- prepare task properties -->
		<SharpDevelopFxCopAssembly Condition="'$(CodeAnalysisInputAssembly)'!=''">$(CodeAnalysisInputAssembly)</SharpDevelopFxCopAssembly>
		<SharpDevelopFxCopAssembly Condition="'$(CodeAnalysisInputAssembly)'==''">$(OutDir)$(TargetName)$(TargetExt)</SharpDevelopFxCopAssembly>
		<SharpDevelopFxCopLogFile Condition="'$(CodeAnalysisLogFile)'!=''">$(CodeAnalysisLogFile)</SharpDevelopFxCopLogFile>
		<SharpDevelopFxCopLogFile Condition="'$(CodeAnalysisLogFile)'==''">$(SharpDevelopFxCopAssembly).CodeAnalysisLog.xml</SharpDevelopFxCopLogFile>
		
		<!-- register custom target -->
		<PrepareForRunDependsOn>$(PrepareForRunDependsOn);SharpDevelopFxCopRun</PrepareForRunDependsOn>
	</PropertyGroup>
	
	<ItemGroup>
		<AvailableItemName Include="CodeAnalysisDictionary" />
	</ItemGroup>
	
	<!-- run SharpDevelop FxCop. -->
	<Target Name="SharpDevelopFxCopRun"
	        Condition="'$(SharpDevelopRunCodeAnalysis)'=='true'"
	        Inputs="$(SharpDevelopFxCopAssembly);@(CodeAnalysisDictionary)"
	        Outputs="$(SharpDevelopFxCopLogFile)"
	        DependsOnTargets="Compile">
		<CreateItem Include = "$(SharpDevelopFxCopLogFile)">
			<Output ItemName = "SharpDevelopFxCopLogFile" TaskParameter="Include"/>
		</CreateItem>
		<FxCop ToolPath       = "$(FxCopDir)"
		       InputAssembly  = "$(SharpDevelopFxCopAssembly)"
		       Rules          = "$(CodeAnalysisRules)"
		       RuleAssemblies = "$(CodeAnalysisRuleAssemblies)"
		       LogFile        = "$(SharpDevelopFxCopLogFile)"
		       ReferencePaths = "@(ReferencePath)"
		       Dictionary     = "@(CodeAnalysisDictionary)"/>
	</Target>
</Project>
