In a .NET Framework project, incompatible with central version management
aetos382 opened this issue · comments
Abstract
When use the DotNet.ReproducibleBuilds.Isolated
SDK in .NET Framework project, it is incompatible with central package version management because it uses the Version
attribute in the <PackageReference>
.
Repro Steps
git clone https://github.com/aetos382/reproducible-builds-issue-report.git
cd reproducible-builds-issue-report
dotnet build
Expected behavior
No error
Actual behavior
error NU1008: Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: Microsoft.NETFramework.ReferenceAssemblies.
Workaround
Manually reference the Microsoft.NETFramework.ReferenceAssemblies
package and define its version in <PackageVersion>
.
Directory.Build.props
<Project>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies"/>
</ItemGroup>
<Sdk Name="DotNet.ReproducibleBuilds.Isolated" Version="1.1.1" />
</Project>
Directory.Packages.props
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2"/>
</ItemGroup>
</Project>
Suggestions for improvement
If central package version management is enabled, use the <PackageVersion>
element to specify the version of the Microsoft.NETFramework.ReferenceAssemblies
package.
Sdk.targets
<Project>
<Target
Name="_EnsureNETFrameworkReferenceAssembliesProvided"
AfterTargets="CheckPackageReferences"
BeforeTargets="CollectPackageReferences"
Condition="
$(TargetFramework.Contains('net4'))
and
'@(PackageReference->AnyHaveMetadataValue('Identity', 'Microsoft.NETFramework.ReferenceAssemblies'))' != 'True'
and
'$(EnsureNETFrameworkReferenceAssembliesProvided)' != 'false'">
<PropertyGroup>
<NETFrameworkReferenceAssembliesVersion>1.0.2</NETFrameworkReferenceAssembliesVersion>
</PropertyGroup>
<PropertyGroup>
<CentralPackageVersionManagementEnabled>false</CentralPackageVersionManagementEnabled>
<CentralPackageVersionManagementEnabled Condition="'$(CentralPackageVersionsFileImported)' == 'true' AND '$(ManagePackageVersionsCentrally)' == 'true'">true</CentralPackageVersionManagementEnabled>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies">
<Version Condition="'$(CentralPackageVersionManagementEnabled)' == 'false'">$(NETFrameworkReferenceAssembliesVersion)</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(CentralPackageVersionManagementEnabled)' == 'true'">
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="$(NETFrameworkReferenceAssembliesVersion)"/>
</ItemGroup>
</Target>
</Project>
UPDATE: I've submitted PR #20.
Environment
- .NET SDK 6.0.400
- DotNet.ReproducibleBuilds.Isolated 1.1.1