-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reasonable Defaults For Centrally Controlled PackageReference Version #54
Reasonable Defaults For Centrally Controlled PackageReference Version #54
Conversation
Utilizing this SDK will now provide "reasonable" default version numbers for PackageReferences even when centrally controlling the versions. Options are present for the 2 common mechanisms: CentralPackageVersionSdk and CentralPackageManagement An informational "Warning" level message is emitted recommending the project owner to add an entry into their package management system of choice... for only those packages that do not have a version controlled entry
This looks very good and well thought out. There are some very clever bits of MSBuild stuff there with metadata and item group transforms but I like it. How much testing have you done to check these work as expected? The only thing I think I would like to tweak is the line that controls the application of the I really like the target with the warning |
The testing I focused on was to create 2 projects (one CPM and one CPV) and walked it through the following phases
For your question about tweaking an area and potentially adding a new property to govern disabling that section, were you referring to this section below? This is the part that sets the "Version" metadata when there is NO central management of package versions, so I'm thinking that we wouldn't ever turn this particular section off. But Maybe I misread your question.
I would love better ideas on the
I whole heartedly agree though, even if most people will never need to set it to false, we should strive to come up with meaningful names. |
Adding a Unit Test Project and two tests
…efault PackageReferences Cherry Pick Unit test from other branch and alter to exercise the Default PackageReference items and Default Version Metadata when Some Flavor of Central Management of Package is enabled on Project Repo This Commit basically adds 3 simple cases 1. No Central Management and SDK adds both PackageReference as well as Version Metadata 2. CentralPackageVersionSdk is presentt but doesn't contain Version metadata for the default packages, and SDK must set the version metadtada 3. CentralPackageManagement is present but doesn't contain Version metadata for the default packages, and SDK must set the version metadata
…ersionDefaultsFromSdk' Tried to come up with a better name for the property that governs this SDKs attempt to provide defaults. Added property to the documentation, and adjusted the language regarding how Version is being set
@CZEMacLeod I added Unit Tests for the 3 simplest of cases. If this seems worthwhile I can add coverage for the other cases as well. And if you have a unit test "Fluent Assertion" flavor preference (should be able to swap in/out whichever one) I added a description about the Property, and the behaviors for version metadata to the documentation Sdk.md. I noticed that the RazorLibrary.md does not currently have the same table describing properties, Should I add a similar one there as well? |
@leusbj I've pushed a small update V4.0.88 which addresses some of the outstanding issues. I've added some info to the documentation for the properties used.
*Version numbers are not applied if you are using You will see that I'm not sure about the unit testing stuff - I think it would need to be added to the build scripts, and the main issue I wanted to ensure was not so much that it worked in all the situations we wanted to cover, but that any other packagereferences in the main project file would not get their version numbers messed up (something I have done in the past when trying to update an item from another item). <PackageReference Update="@(PackageReference->WithMetadataValue('SystemWebSdkIncludedPackage','true')->HasMetadata('SystemWebSdkIncludedPackageVersion'))"
Condition=" '$(UsingMicrosoftCentralPackageVersionsSdk)' != 'true' AND '$(ManagePackageVersionsCentrally)' != 'true' ">
<Version>%(SystemWebSdkIncludedPackageVersion)</Version>
</PackageReference> to make sure that it does not overwrite all packagereferences or updates them all to the value of %(SystemWebSdkIncludedPackageVersion) of last one matched. As I said, assuming this logic behaves correctly I really like everything done here. |
|
||
|
||
<PackageReference Update="@(PackageReference->WithMetadataValue('SystemWebSdkIncludedPackage','true')->HasMetadata('SystemWebSdkIncludedPackageVersion'))" | ||
Condition=" '$(UsingMicrosoftCentralPackageVersionsSdk)' != 'true' AND '$(ManagePackageVersionsCentrally)' != 'true' "> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use '$(ApplySDKDefaultPackageVersions)'=='true'
as the condition as of V4.0.88
This should probably be in the common files target now.
@@ -0,0 +1,100 @@ | |||
<!-- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should probably be a common file now, and use the ExcludeSDKDefaultPackages
and ApplySDKDefaultPackageVersions
properties instead of ExcludeDefaultRazorPackages
and EnablePackageVersionDefaultsFromSdk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to take a look at it in the next several days.
src/MSBuild.SDK.SystemWeb/Sdk/MSBuild.SDK.SystemWeb.DefaultPackageControlledVersions.targets
Outdated
Show resolved
Hide resolved
It looks good to me as well. I agree that there was some clever MSBuild work in here. I kept circling back in my free time trying to think how to solve the issues @CZEMacLeod and you had presented but I hadn't come up with a set that addressed everything. I would like to assist in testing this after the rebase and outstanding issues are addressed. Let me know how I can help. |
@CZEMacLeod
|
|
+ Centralized "{PackageName}_Version" properties into a Common file + Centralized the application of Version Metadata into a Common file + Centralized the Target to emit warnings when centralized logic detected and this SDK was forced to apply a default + Updated a "pathing" check to something more stable + Updated Documentation to document changes to the `ApplySDKDefaultPackageVersions` property
samples/ExampleFullWebApplication/ExampleFullWebApplication.vbproj
Outdated
Show resolved
Hide resolved
...ld.SDK.SystemWeb.CommonFiles/Sdk/MSBuild.SDK.SystemWeb.Common.DefaultPackageVersions.targets
Show resolved
Hide resolved
@@ -2,5 +2,8 @@ | |||
<PropertyGroup Condition="'$(ExcludeSDKDefaultPackages)'=='false'"> | |||
<MicrosoftNetCompilersToolset_Version Condition="'$(MicrosoftNetCompilersToolset_Version)'==''">4.5.0</MicrosoftNetCompilersToolset_Version> | |||
<MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version Condition="'$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)'==''">3.6.0</MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version> | |||
<MicrosoftAspNetMvc_Version Condition="'$(MicrosoftAspNetMvc_Version)'==''">5.2.9</MicrosoftAspNetMvc_Version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you have moved these from the RazorLibrary specific DefaultPackages files.
As these are not used in the main SDK (currently), I'm not sure that I like having them defined without purpose.
My idea was that all common packages/versions would be in Common, and any specific to either the main SDK or RazorLibrary SDK would be in the specific one.
Is there a reason for this move that I am missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No special purpose at the moment. I'll put them back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you've copied them back, but not removed them here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Removed unnecessary UnitTest1.cs Removed inline Sdk Version from ExampleFullWebApplication Placed default Package Version numbers back under RazorLibrary Added explicit conditional checks when gathering "Suggestions"
@CZEMacLeod I've incorporated your feedback (and added comments to your questions). Do you want me to take a stab at adding a "Unit Test" to the Potentially something like - task: VSTest@2
displayName: 'Run Unit Tests'
inputs:
testAssemblyVer2: |
**\MSBuild.SDK.SystemWeb*.UnitTests*.dll
!**\obj\**
codeCoverageEnabled: true
diagnosticsEnabled: True I don't know how/if I can experiment with that, and I don't want to break your pipeline, so I'm hesitant to include that into a PR |
You can certainly add that in. At the moment the pipeline doesn't run for PRs, and I can mess with it (if need be) once this is merged. |
</ItemGroup> | ||
<ItemGroup Condition=" '$(ExcludeSDKDefaultPackages)'=='false' "> | ||
<PackageReference Include="Microsoft.Net.Compilers.Toolset" | ||
Condition="'$(MicrosoftNetCompilersToolset_Version)'!=''" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these shouldn't have the condition of the version on them, as they may not have versions set if using CPM/CPV.
Would it be better to create a new item group, e.g. SDKDefaultPackageReference
with these, then at the end of common do a
<PackageReference Include="@(SDKDefaultPackageReference)"
Exclude="@(PackageReference)"
Condition="'$(ExcludeSDKDefaultPackages)'=='false'">
<Version /><!-- Make sure we don't apply version's here -->
<SystemWebSdkIncludedPackage>true</SystemWebSdkIncludedPackage>
<SystemWebSdkIncludedPackageVersion>%(Version)</SystemWebSdkIncludedPackageVersion>
</PackageReference>
or is that adding complexity that it doesn't need? (Would need to import common at the end of razor/sdk defaultpackages instead of the start.)
I just think that having simple to manage lines for the default package refs (and any custom properties such as PrivateAssets
, or GeneratePathProperty
) would make it simpler to read and maintain - e.g. if adding a new reference.
<ItemGroup>
<SDKDefaultPackageReference Include="Microsoft.Net.Compilers.Toolset"
Version="$(MicrosoftNetCompilersToolset_Version)"
PrivateAssets="All"
GeneratePathProperty="true" />
<SDKDefaultPackageReference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform"
Version="$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)" />
</ItemGroup>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional check on named version property
That Conditional on the version property is a holdover from back before your recent updates.
Previously it looked like this
<ItemGroup Condition="'$(ExcludeASPNetCompilers)'=='false' AND '$(UsingMicrosoftCentralPackageVersionsSdk)'!='true'">
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="$(MicrosoftNetCompilersToolset_Version)" PrivateAssets="All" Condition="'$(MicrosoftNetCompilersToolset_Version)'!=''"/>
<PackageReference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" Version="$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)" Condition="'$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)'!=''" />
</ItemGroup>
I had assumed that it was an intentional way of allowing project owners to exclude an individual package (clear out property for single named package), so I had included that old conditional in this rendition. But we can probably go with ExcludeSDKDefaultPackages
as the sole decision point.
Separate ItemGroup
I had thought about having some itemgroup that is the list of packages we will work on, but we already have named properties for each package and that is a fairly straight forward way for project owners to tweak if they want to.
In general, I think whatever these end up being, they still needs to be "incorporated" in 2 phases though
- Ensure that the items are added to
PackageReference
item group (without adding duplicates)... so after projectfile, but before Directory.Build.targets - Ensure appropriate Version metadata is in place... this could be
PackageReference
orPackageVersion
depending on which mechanism is at work... so after Directory.Build.targets
I'll think on it some more
Closing this PR for now, as the goals and design has moved quite a long way since this version |
Here's a potential Approach for #46 and #49
Utilizing this SDK will now provide "reasonable" default version numbers for certain PackageReferences
Packages.targets
does not provide version value)Directory.Packages.targets
does not provide version value)This Sdk will provide an inforrmational "Warning" level message during build recommending the project owner to add an entry into their package management system of choice... for those packages that do not have a centralized version entry, and the Sdk default value was applied.
@brandon-hurler and @CZEMacLeod See if this aligns with what you were looking for