Skip to content

Disallow usage of $(NetCoreAppCurrent) in projects that don't exclude such configuration and generate a package #48311

Closed

Description

@ViktorHofer

With 6.0 Preview 1 there were a few packages that unintentionally contain a net6.0 configuration:

Reason for that is that these packages use the $(NetCoreAppCurrent) msbuild property which maps to .NETCoreApp version which is currently in development (i.e. net6.0) instead of a fixed version which doesn't automatically rev forward.

What makes it tricky to prohibit the usage of $(NetCoreAppCurrent) in packages that don't exclude it and generate package is that this would need to happen before msbuild evaluation, as the $(NetCoreAppCurrent) token gets replaced with the property value.

cc @Anipik @ericstj

Activity

  1. added this to the Future milestone on Feb 15, 2021
  2. ghost added
    untriaged
    on Feb 15, 2021
  3. removed
    untriaged
    on Feb 15, 2021
  4. safern commented on Feb 16, 2021

    @safern
    Member

    Something to consider here is that sometimes we need to use a new API or feature in some of these packages that is only available in NetcoreAppCurrent. So there are releases where we need to include an asset for NetcoreAppCurrent in the package. So we need a way to either turn off that error or prevent those packages from being blocked in shipping an asset for NetcoreAppCurrent.

    That is what I suspect happened with these packages and when we moved the property to point to net6.0, we forgot to add the exclusion on those packages.

  5. ViktorHofer commented on Feb 16, 2021

    @ViktorHofer
    MemberAuthor

    So there are releases where we need to include an asset for NetcoreAppCurrent in the package.

    Absolutely. I'm talking about disallowing the use of the literal $(NetCoreAppCurrent) string in favor of the inlined value, i.e. net6.0.

    I believe this could be part of the package validation by reading the project file and searching for $(NetCoreAppCurrent). Pseudo code:

    <Target Name="WarnForVersionlessTfm" BeforeTargets="Pack" Condition="'$(IsPackable)' == 'true'">
      <PropertyGroup>
        <_ProjectFileContent>$([System.IO.File]::ReadAllText('$(MSBuildThisProjectFile)'))</ProjectFileContent>
      </PropertyGroup>
      <Warn Message="The replacement token '$(NetCoreAppCurrent)' must not be used in a project that generates a package which doesn't exclude such configuration via the `<ExcludeCurrentNetCoreAppFromPackage />` property." Condition="'$(ExcludeCurrentNetCoreAppFromPackage)' != 'true' and $(ProjectFileContent.Contains('%24(NetCoreAppCurrent)'))" />
    </Target>
    

    It would be better to use a regex search here to only look at the content inside the <TargetFramework(s) /> string.

  6. ViktorHofer commented on Aug 6, 2021

    @ViktorHofer
    MemberAuthor

    Closing as we now intentionally include $(NetCoreAppCurrent) assets in our packages.

  7. ghost locked as resolved and limited conversation to collaborators on Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions