Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Adopt central package versions (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Sep 7, 2017
1 parent 8ef3ecb commit 08fffe7
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 18 deletions.
6 changes: 6 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(MSBuildThisFileDirectory)build\CheckPackageReferences.targets" />

</Project>
30 changes: 30 additions & 0 deletions Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildThisFileFullPath);$(MSBuildAllProjects)</MSBuildAllProjects>
</PropertyGroup>

<ItemGroup Label="Package versions used by this repository">
<!--
When referencing a new package, update this list with a matching Include and the desired version. When updating
a package, remove the Version from an individual project and update the Version in this file instead.
-->
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="[15.3.409]" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="[15.3.0]" />
<PackageVersion Include="Microsoft.NETCore.App" Version="[1.1.2]" />
<PackageVersion Include="NUnit" Version="[3.8.1]" />
<PackageVersion Include="NUnit3TestAdapter" Version="[3.8.0]" />
<PackageVersion Include="NETStandard.Library" Version="[1.6.1]" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="[2.0.37-beta]" PrivateAssets="All" />
<PackageVersion Include="Shouldly" Version="[2.8.2]" />
</ItemGroup>

<ItemGroup Label="Packages to add to all projects">
<!--
To reference a package in all projects, add it to this list. Be sure to specify also specify a PackageVersion above.
-->
<GlobalPackageReference Include="Nerdbank.GitVersioning" Condition=" '$(EnableGitVersioning)' != 'false' " />
</ItemGroup>

</Project>
93 changes: 93 additions & 0 deletions build/CheckPackageReferences.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<Project InitialTargets="CheckPackageReferences" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildThisFileFullPath);$(MSBuildAllProjects)</MSBuildAllProjects>
<CentralPackagesFile Condition=" '$(CentralPackagesFile)' == '' ">$([MSBuild]::GetPathOfFileAbove('Packages.props'))</CentralPackagesFile>
</PropertyGroup>

<ItemGroup>
<!-- Stores the package versions specified in individual projects -->
<ProjectSpecifiedPackageVersion Include="@(PackageVersion)" />
</ItemGroup>

<Import Project="$(CentralPackagesFile)" />

<ItemGroup>

<!-- Clear package versions that are duplicated from a project and the central package versions file -->
<PackageVersion Remove="@(ProjectSpecifiedPackageVersion)" />

<!-- Add back the project specified package versions -->
<PackageVersion Include="@(ProjectSpecifiedPackageVersion)" />

<!-- Stores the original package references used later to determine if there are any problems -->
<OriginalPackageReference Include="@(PackageReference)" />

<!-- Add global package references -->
<PackageReference Include="@(GlobalPackageReference)" />

<!-- Store all PackageVersion items that do not have a PackageReference -->
<_PackagesNotReferenced Include="@(PackageVersion)" Exclude="@(PackageReference)" />

<!-- Clear the PackageReference list -->
<PackageReference Remove="@(OriginalPackageReference);@(GlobalPackageReference)" />

<!-- Add back the PackageReference its from the list that contains versions, excluding the items not referenced -->
<PackageReference Include="@(PackageVersion)" Exclude="@(_PackagesNotReferenced)" />

<!-- Clear the temporary list of items not referenced -->
<_PackagesNotReferenced Remove="@(_PackagesNotReferenced)" />

</ItemGroup>

<Target Name="CheckPackageReferences"
Condition=" '@(PackageReference)' != '' ">

<ItemGroup>
<!--
Determine all of the original PackageReference items that did not have a PackageVersion
-->
<MissingPackageReference Include="@(OriginalPackageReference)" Exclude="@(PackageVersion)" />

<!--
Determine all of the PackageReference items that are already declared as GlobalPackageReference items.
-->
<DuplicateGlobalPackageReference Include="@(OriginalPackageReference)" Condition=" '@(GlobalPackageReference)' == '@(OriginalPackageReference)' and '%(Identity)' != '' " />
</ItemGroup>

<!--
Generate an error if any PackageReference has a version specified and its not an implicit item
-->
<Error
Text="The package reference '%(OriginalPackageReference.Identity)' should not specify a version. Please specify the version in '$(CentralPackagesFile)'."
Condition=" '%(OriginalPackageReference.IsImplicitlyDefined)' != 'true' And '%(OriginalPackageReference.Version)' != '' "
File="$(MSBuildProjectFullPath) "/>

<!--
Generate an error if any explicit PackageReference did not have matching PackageVersion
-->
<Error
Text="The package reference '%(MissingPackageReference.Identity)' must have a version defined in '$(CentralPackagesFile)'."
Condition=" '@(MissingPackageReference)' != '' And '%(MissingPackageReference.IsImplicitlyDefined)' != 'true' "
File="$(MSBuildProjectFullPath)" />

<!--
Generate an error if any implicit PackageReference did not have matching PackageVersion
-->
<Error
Text="The implicit package reference '%(MissingPackageReference.Identity)' must have a version defined in '$(CentralPackagesFile)'."
Condition=" '@(MissingPackageReference)' != '' And '%(MissingPackageReference.IsImplicitlyDefined)' == 'true' "
File="$(MSBuildProjectFullPath)" />

<!--
Generate an error if any project specified a PackageReference and there is already the same GlobalPackageReference
-->
<Error
Text="The package reference '%(DuplicateGlobalPackageReference.Identity)' is already defined as a GlobalPackageReference in '$(CentralPackagesFile)'. Individual projects do not need to include a PackageReference if a GlobalPackageReference is declared."
Condition=" '@(DuplicateGlobalPackageReference)' != '' "
File="$(MSBuildProjectFullPath)" />

</Target>

</Project>
11 changes: 9 additions & 2 deletions src/MSBuildArgs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26828.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Build.CommandLine.Arguments", "Microsoft.Build.CommandLine.Arguments\Microsoft.Build.CommandLine.Arguments.csproj", "{2574A969-934C-439F-BBC0-6D46F7CE1FFA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.CommandLine.Arguments", "Microsoft.Build.CommandLine.Arguments\Microsoft.Build.CommandLine.Arguments.csproj", "{2574A969-934C-439F-BBC0-6D46F7CE1FFA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Build.CommandLine.Arguments.UnitTests", "Microsoft.Build.CommandLine.Arguments.UnitTests\Microsoft.Build.CommandLine.Arguments.UnitTests.csproj", "{510FC774-5E9C-4B55-A015-0C2A7F55861A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.CommandLine.Arguments.UnitTests", "Microsoft.Build.CommandLine.Arguments.UnitTests\Microsoft.Build.CommandLine.Arguments.UnitTests.csproj", "{510FC774-5E9C-4B55-A015-0C2A7F55861A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6CA84474-1B0F-4CA4-98FE-195BF8D230C1}"
ProjectSection(SolutionItems) = preProject
..\Directory.Build.targets = ..\Directory.Build.targets
..\Packages.props = ..\Packages.props
..\version.json = ..\version.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
<PackageReference Include="Shouldly" Version="2.8.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Shouldly" />

<ProjectReference Include="..\Microsoft.Build.CommandLine.Arguments\Microsoft.Build.CommandLine.Arguments.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.3.409" />
<PackageReference Include="Microsoft.Build.Utilities.Core" />
</ItemGroup>

<!--<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="NETStandard.Library" Version="1.6.0" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.1.262-preview5" />
</ItemGroup>-->

<!--<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>-->

</Project>
24 changes: 24 additions & 0 deletions version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.0", // required
"assemblyVersion": "1.0", // optional. Use when x.y for AssemblyVersionAttribute differs from the default version property.
"buildNumberOffset": 0, // optional. Use when you need to add/subtract a fixed value from the computed build number.
"semVer1NumericIdentifierPadding": 4, // optional. Use when your -prerelease includes numeric identifiers and need semver1 support.
"nugetPackageVersion": {
"semVer": 1 // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1.
},
"publicReleaseRefSpec": [
"^refs/heads/master$", // we release out of master
"^refs/tags/v\\d+\\.\\d+" // we also release tags starting with vN.N
],
"cloudBuild": {
"setVersionVariables": true,
"buildNumber": {
"enabled": false,
"includeCommitId": {
"when": "nonPublicReleaseOnly",
"where": "buildMetadata"
}
}
}
}

0 comments on commit 08fffe7

Please sign in to comment.