Skip to content

Commit

Permalink
Improve build for new NuGet targets
Browse files Browse the repository at this point in the history
MSBuild tools version is generally does not correlate with the Visual
Studio or SDK version, and the changes between different versions of
scripts under Contracts/MsBuild/ were inconsequential anyway. We now
use a common set of build files for all MSBuild versions 4.0 and above.

See dotnet/msbuild#52 (comment)
for the elaboration on the versioning conventions.
  • Loading branch information
kkm committed Dec 21, 2017
1 parent cb52a7f commit 45d52d1
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 2,742 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Changed
- Build uses single set of target files for all MSBuild versions 4.0 and above.

## [1.11-alpha] - 2017-12-02
### Added
- Added change log
Expand Down
254 changes: 0 additions & 254 deletions Contracts/MsBuild/v12.0/Microsoft.CodeContractAnalysis.targets

This file was deleted.

646 changes: 0 additions & 646 deletions Contracts/MsBuild/v12.0/Microsoft.CodeContracts.targets

This file was deleted.

254 changes: 0 additions & 254 deletions Contracts/MsBuild/v14.0/Microsoft.CodeContractAnalysis.targets

This file was deleted.

646 changes: 0 additions & 646 deletions Contracts/MsBuild/v14.0/Microsoft.CodeContracts.targets

This file was deleted.

254 changes: 0 additions & 254 deletions Contracts/MsBuild/v15.0/Microsoft.CodeContractAnalysis.targets

This file was deleted.

646 changes: 0 additions & 646 deletions Contracts/MsBuild/v15.0/Microsoft.CodeContracts.targets

This file was deleted.

24 changes: 12 additions & 12 deletions Contracts/MsBuild/v4.0/Microsoft.CodeContractAnalysis.targets
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
Condition="'$(CodeContractsClassLibrary)' != ''">$(CodeContractCodeAnalysisOptions) -cclib "$(CodeContractsClassLibrary)"</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsAssemblyMode)' == '1'">$(CodeContractCodeAnalysisOptions) -assemblyMode=standard</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions>$(CodeContractCodeAnalysisOptions) -maxwarnings 400</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions>$(CodeContractCodeAnalysisOptions) -maxwarnings 1200</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsNonNullObligations)' != 'true'">$(CodeContractCodeAnalysisOptions) -nonnull:noObl</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Expand All @@ -160,7 +160,7 @@
Condition="'$(CodeContractsRedundantAssumptions)' == 'true'">$(CodeContractCodeAnalysisOptions) -check assumptions</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsAssertsToContractsCheckBox)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest asserttocontracts</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsRedundantTests)' == 'true'">$(CodeContractCodeAnalysisOptions) -check conditionsvalidity</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsMissingPublicRequiresAsWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -missingPublicRequiresAreErrors</CodeContractCodeAnalysisOptions>
Expand All @@ -170,29 +170,29 @@
Condition="'$(CodeContractsSuggestAssumptionsForCallees)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest calleeassumes</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestAssumptions)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest assumes</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestRequires)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest requires</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestEnsures)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest methodensures -suggest propertyensures</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsInferEnsuresAutoProperties)' == 'true'">$(CodeContractCodeAnalysisOptions) -infer autopropertiesensures</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestEnsures)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest methodensures -suggest propertyensures</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsNecessaryEnsures)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest necessaryensures</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestObjectInvariants)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest objectinvariants</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSuggestReadonly)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest readonlyfields </CodeContractCodeAnalysisOptions>
Condition="'$(CodeContractsSuggestReadonly)' == 'true'">$(CodeContractCodeAnalysisOptions) -suggest readonlyfields</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsInferRequires)' == 'true'">$(CodeContractCodeAnalysisOptions) -infer requires</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsInferEnsures)' == 'true'">$(CodeContractCodeAnalysisOptions) -infer methodensures</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsInferEnsuresAutoProperties)' == 'true'">$(CodeContractCodeAnalysisOptions) -infer autopropertiesensures</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsInferObjectInvariants)' == 'true'">$(CodeContractCodeAnalysisOptions) -infer objectinvariants</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsCacheAnalysisResults)' == 'true'">$(CodeContractCodeAnalysisOptions) -cache</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsSkipAnalysisIfCannotConnectToCache)' == 'true'">$(CodeContractCodeAnalysisOptions) -forcecacheserver=true</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsFailBuildOnWarnings)' == 'true'">$(CodeContractCodeAnalysisOptions) -failOnWarnings</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsCacheDirectory)' != ''">$(CodeContractCodeAnalysisOptions) -cacheFileDirectory "$(CodeContractsCacheDirectory)"</CodeContractCodeAnalysisOptions>
Expand All @@ -206,7 +206,7 @@
Condition="'$(CodeContractsTargetType)' != ''">$(CodeContractCodeAnalysisOptions) -typeNameSelect:$(CodeContractsTargetType)</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsBeingOptimisticOnExternal)' == 'false'">$(CodeContractCodeAnalysisOptions) -lowScoreForExternal=false</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsTargetNamespace)' != ''">$(CodeContractCodeAnalysisOptions) -namespaceSelect:$(CodeContractsTargetNamespace)</CodeContractCodeAnalysisOptions>
<CodeContractCodeAnalysisOptions
Condition="'$(CodeContractsUseBaseLine)' == 'true' and '$(CodeContractsBaseLineFile)' != ''">$(CodeContractCodeAnalysisOptions) -baseline "$(CodeContractsBaseLineFile)"</CodeContractCodeAnalysisOptions>
Expand Down
55 changes: 27 additions & 28 deletions Contracts/MsBuild/v4.0/Microsoft.CodeContracts.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</PropertyGroup>

<!--=====================================================================
Begin Microsoft Code Contracts
Begin Microsoft Code Contracts
======================================================================-->

<PropertyGroup>
<CodeContractsDeclDir>$(OutDir)CodeContractsDeclarative\</CodeContractsDeclDir>
<CodeContractsDeclDir>$(IntermediateOutputPath)Decl\</CodeContractsDeclDir>
<CodeContractsContractSubDir>CodeContracts\</CodeContractsContractSubDir>
<CodeContractsCCRefgenCommand>$(CodeContractsInstallDir)Bin\ccrefgen.exe</CodeContractsCCRefgenCommand>
</PropertyGroup>
Expand Down Expand Up @@ -50,14 +50,14 @@
<CodeContractsReferenceAssemblyLibPath>$(CodeContractsInstallDir)Contracts\.NETFramework\v4.0</CodeContractsReferenceAssemblyLibPath>
</PropertyGroup>
</When>
<When Condition="'$(TargetFrameworkVersion)' == 'v4.5'">
<When Condition="$(TargetFrameworkVersion.StartsWith('v4.5'))">
<PropertyGroup>
<CodeContractsReferenceAssemblyLibPath>$(CodeContractsInstallDir)Contracts\.NETFramework\v4.5</CodeContractsReferenceAssemblyLibPath>
</PropertyGroup>
</When>
<When Condition="'$(TargetFrameworkVersion)' == 'v4.5.1'">
<When Condition="$(TargetFrameworkVersion.StartsWith('v4.'))">
<PropertyGroup>
<CodeContractsReferenceAssemblyLibPath>$(CodeContractsInstallDir)Contracts\.NETFramework\v4.5</CodeContractsReferenceAssemblyLibPath>
<CodeContractsReferenceAssemblyLibPath>$(CodeContractsInstallDir)Contracts\.NETFramework\v4.6</CodeContractsReferenceAssemblyLibPath>
</PropertyGroup>
</When>
<Otherwise>
Expand All @@ -77,7 +77,7 @@
VS property build pane picks it up and may persist it into the project
settings!
=====================================================================-->

<PropertyGroup>
<CompileDependsOn>CodeContractsSlipInDefineSymbolDynamically;$(CompileDependsOn);CodeContractReferenceAssembly</CompileDependsOn>
</PropertyGroup>
Expand Down Expand Up @@ -271,24 +271,26 @@

<Target
Name="CodeContractReSign"
Condition="'$(DelaySign)' != 'true'"
Condition="'$(DelaySign)' != 'true'"
>
<GetFrameworkSdkPath>
<Output
TaskParameter="Path"
PropertyName="CodeContractsSdkPath" />
</GetFrameworkSdkPath>
<PropertyGroup>
<CodeContractsSnExe>"$(CodeContractsSdkPath)Bin\NETFX 4.0 Tools\sn.exe"</CodeContractsSnExe>
<!-- SN is in the Framework SDK tools path, but TargetFrameworkSDKToolsDirectory isn't always available -->
<CodeContractsSnExe Condition=" '$(TargetFrameworkSDKToolsDirectory)' != '' ">$(TargetFrameworkSDKToolsDirectory)sn.exe</CodeContractsSnExe>
<CodeContractsSnExe Condition=" '$(TargetFrameworkSDKToolsDirectory)' == '' ">$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.6 Tools\sn.exe</CodeContractsSnExe>
</PropertyGroup>
<Exec
Condition="'$(KeyOriginatorFile)' != ''"
Command='$(CodeContractsSnExe) /R "@(IntermediateAssembly)" "$(KeyOriginatorFile)"' />
Condition="'$(KeyOriginatorFile)' != ''"
Command='&quot;$(CodeContractsSnExe)&quot; /R "@(IntermediateAssembly)" "$(KeyOriginatorFile)"' />
<Exec
Condition="'$(KeyContainerName)' != ''"
Command='$(CodeContractsSnExe) /Rc "@(IntermediateAssembly)" "$(KeyContainerName)"' />
Condition="'$(KeyContainerName)' != ''"
Command='&quot;$(CodeContractsSnExe)&quot; /Rc "@(IntermediateAssembly)" "$(KeyContainerName)"' />
</Target>

<Target
Name="CodeContractInstrument"
Condition="'$(CodeContractsEnableRuntimeChecking)' == 'true' and '$(BuildingProject)'=='true'"
Expand Down Expand Up @@ -374,7 +376,7 @@
Name="MakeCodeContractOutputDirectory"
Condition="!Exists(@(CodeContractOutputDirectory))"
>
<Message
<Message
Text="Making directory @(CodeContractOutputDirectory)"
/>
<MakeDir
Expand Down Expand Up @@ -415,7 +417,7 @@
Condition="!Exists('$(CodeContractsDeclDir)')"
Directories="$(CodeContractsDeclDir)"/>
</Target>

<Target
Name="ContractDeclarativeAssemblyVB"
Condition="'$(Language)'=='VB'"
Expand All @@ -431,7 +433,7 @@
<Vbc Condition=" '%(_CoreCompileResourceInputs.WithCulture)' != 'true' "
AdditionalLibPaths="$(AdditionalLibPaths)"
AddModules="@(AddModules)"
BaseAddress="$(BaseAddress)"
BaseAddress="$(BaseAddress)"
CodePage="$(CodePage)"
DebugType="$(DebugType)"
DefineConstants="$(FinalDefineConstants),CONTRACTS_FULL=-1,CODE_ANALYSIS=-1"
Expand All @@ -458,7 +460,7 @@
OptionExplicit="$(OptionExplicit)"
OptionInfer="$(OptionInfer)"
OptionStrict="$(OptionStrict)"
OptionStrictType="$(OptionStrictType)"
OptionStrictType="$(OptionStrictType)"
OutputAssembly="@(ContractDeclarativeAssembly)"
Platform="$(PlatformTarget)"
References="@(ReferencePath)"
Expand All @@ -479,10 +481,10 @@
WarningsAsErrors=""
WarningsNotAsErrors="$(WarningsNotAsErrors)"
Win32Icon="$(ApplicationIcon)"
Win32Manifest="$(Win32Manifest)"
Win32Manifest="$(Win32Manifest)"
Win32Resource="$(Win32Resource)"
/>

<ItemGroup>
<FileWrites
Include="@(ContractDeclarativeAssemblies)"/>
Expand Down Expand Up @@ -528,7 +530,7 @@
NoWin32Manifest="$(NoWin32Manifest)"
Optimize="true"
OutputAssembly="@(ContractDeclarativeAssembly)"
PdbFile="@(ContractDeclarativeAssemblyPDB)"
PdbFile="@(ContractDeclarativeAssemblyPDB)"
Platform="$(PlatformTarget)"
References="@(ReferencePath)"
Resources=""
Expand All @@ -546,8 +548,8 @@
Win32Icon=""
Win32Manifest="$(Win32Manifest)"
Win32Resource="$(Win32Resource)"
/>
/>

<ItemGroup>
<FileWrites
Include="@(ContractDeclarativeAssemblies)"/>
Expand Down Expand Up @@ -628,17 +630,14 @@
/>

<Exec
Command='"$(CodeContractsCCdocgenCommand)" "@$(IntermediateOutputPath)$(ProjectName)ccdocgen.rsp"'
Command='"$(CodeContractsCCdocgenCommand)" "@$(IntermediateOutputPath)$(ProjectName)ccdocgen.rsp"'
/>
</Target>

<!--=====================================================================
Include Code Analysis target if present
Include Code Analysis target
======================================================================-->
<PropertyGroup>
<CodeContractAnalysisTargets>$(CodeContractsInstallDir)MsBuild\v4.0\Microsoft.CodeContractAnalysis.targets</CodeContractAnalysisTargets>
</PropertyGroup>
<Import Project="$(CodeContractAnalysisTargets)" Condition="Exists('$(CodeContractAnalysisTargets)')"/>
<Import Project="Microsoft.CodeContractAnalysis.targets" />

<!-- End Microsoft Code Contracts -->
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CodeContractsInstallDir Condition="'$(DontOverrideCodeContractsInstallDir)' != 'true'">$(MSBuildThisFileDirectory)..\Contracts\</CodeContractsInstallDir>
<_CodeContractsBuildToolsVersion Condition="$(MSBuildToolsVersion) &lt; 4.0">3.5</_CodeContractsBuildToolsVersion>
<_CodeContractsBuildToolsVersion Condition="$(MSBuildToolsVersion) &gt;= 4.0">4.0</_CodeContractsBuildToolsVersion>
</PropertyGroup>
<Import Condition="'$(CodeContractsImported)' != 'true' AND '$(DontImportCodeContracts)' != 'true'" Project="$(CodeContractsInstallDir)MsBuild\v$(MSBuildToolsVersion)\Microsoft.CodeContracts.targets" />
<Import Condition="'$(CodeContractsImported)' != 'true' AND '$(DontImportCodeContracts)' != 'true'" Project="$(CodeContractsInstallDir)MsBuild\v$(_CodeContractsBuildToolsVersion)\Microsoft.CodeContracts.targets" />
</Project>

0 comments on commit 45d52d1

Please sign in to comment.