Skip to content
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

PublishSNIFiles is part of PublishItemsOutputGroupDependsOn, but doesn't contribute to PublishItemsOutputGroupOutputs #3081

Open
austindrenski opened this issue Dec 11, 2024 · 0 comments
Labels
🐛 Bug! Issues that are bugs in the drivers we maintain. ✔️ Triage Done Issues that are triaged by dev team and are in investigation.

Comments

@austindrenski
Copy link

Describe the bug

Microsoft.Data.SqlClient.SNI.targets adds PublishSNIFiles to PublishItemsOutputGroupDependsOn, but it doesn't add the published SNI files to PublishItemsOutputGroupOutputs.

I can't seem to find the source for this targets file on GitHub, so for reference, here's what it looks like on my local:

<!-- ~/.nuget/packages/microsoft.data.sqlclient.sni/5.2.0/buildTransitive/net462/Microsoft.Data.SqlClient.SNI.targets -->

  <Target Name="PublishSNIFiles" AfterTargets="Publish"
          Condition="'$(CopySNIFiles)' != 'false' And
                     '$(PublishSNIFiles)' != 'false' And
                     '$(PublishDir)' != '' And
                     '$(_DeploymentApplicationDir)' == '' And
                     HasTrailingSlash('$(PublishDir)') And
                     Exists('$(PublishDir)') And
                     '@(ClickOnce)' != ''"
          Inputs="@(SNIDllFiles)"
          Outputs="@(SNIDllFiles -> '$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')">
    <!--
        NOTE: Copy "Microsoft.Data.SqlClient.SNI.dll" only to the publish directory.

    -->
    <Copy SourceFiles="@(SNIDllFiles)"
          DestinationFiles="@(SNIDllFiles -> '$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')" />
  </Target>

It seems like this target should take the additional step of adding the SNI files to @(PublishItemsOutputGroupOutputs) so that downstream targets are aware that these items are part of the published output, e.g.:

  <Target Name="PublishSNIFiles" AfterTargets="Publish"
          Condition="'$(CopySNIFiles)' != 'false' And
                     '$(PublishSNIFiles)' != 'false' And
                     '$(PublishDir)' != '' And
                     '$(_DeploymentApplicationDir)' == '' And
                     HasTrailingSlash('$(PublishDir)') And
                     Exists('$(PublishDir)') And
                     '@(ClickOnce)' != ''"
          Inputs="@(SNIDllFiles)"
          Outputs="@(SNIDllFiles -> '$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')">
    <!--
        NOTE: Copy "Microsoft.Data.SqlClient.SNI.dll" only to the publish directory.

    -->
    <Copy SourceFiles="@(SNIDllFiles)"
          DestinationFiles="@(SNIDllFiles -> '$(PublishDir)%(RecursiveDir)%(Filename)%(Extension)')" />

+   <ItemGroup>
+     <PublishItemsOutputGroupOutputs Include="@(SNIDllFiles)"
+                                     TargetPath="@(SNIDllFiles -> '%(Filename)%(Extension)')"
+                                     IsKeyOutput="true"
+                                     Condition="'@(SNIDllFiles)' != ''"
+                                     OutputPath="$(PublishDir)%(RecursiveDir)"
+                                     OutputGroup="PublishItemsOutputGroup" />
+   </ItemGroup>
  </Target>

To reproduce

<!-- SomeProject.csproj -->
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
  </ItemGroup>

  <Target Name="CreateDeployPackage" AfterTargets="AfterSdkPublish">

    <!--
      The logic here doesn't really matter, but including this to demonstrate what this 
      looks like in practice. The key take-away is that at the end, we want PublishDir
      to look something like this:

        PublishDir/
          SomeProject.1.0.0.zip

      but at present, we find something like this:

        PublishDir/
          SomeProject.1.0.0.zip
          Microsoft.Data.SqlClient.SNI.arm64.dll
          Microsoft.Data.SqlClient.SNI.x64.dll
          Microsoft.Data.SqlClient.SNI.x86.dll

    -->
    <Move SourceFiles="@(PublishItemsOutputGroupOutputs->'%(OutputPath)')" DestinationFolder="$(PublishDir)/$(MSBuildProjectName).$(Version)" />
    <ZipDirectory SourceDirectory="$(PublishDir)/$(MSBuildProjectName).$(Version)" DestinationFile="$(PublishDir)/$(MSBuildProjectName).$(Version).zip" />

    <ItemGroup>
      <_OrphanedFiles Include="$(PublishDir)/*" Exclude="$(PublishDir)/*.zip" />
    </ItemGroup>

    <Warning Text="@(_OrphanedFiles)" />

  </Target>

</Project>
$ dotnet publish
    warning : bin\Debug\net48\publish\Microsoft.Data.SqlClient.SNI.arm64.dll;bin\Debug\net48\publish\Microsoft.Data.SqlClient.SNI.x64.dll;bin\Debug\net48\publish\Microsoft.Data.SqlClient.SNI.x86.dll

Build succeeded with 1 warning(s) in 1.3s

$ ls -1 bin/Debug/net48/publish/
Microsoft.Data.SqlClient.SNI.arm64.dll
Microsoft.Data.SqlClient.SNI.x64.dll
Microsoft.Data.SqlClient.SNI.x86.dll
SomeProject.1.0.0.zip

Expected behavior

$ dotnet publish

Build succeeded in 1.3s

$ ls -1 bin/Debug/net48/publish/
SomeProject.1.0.0.zip
@austindrenski austindrenski added 🐛 Bug! Issues that are bugs in the drivers we maintain. 🆕 Triage Needed For new issues, not triaged yet. labels Dec 11, 2024
@mdaigle mdaigle added ✔️ Triage Done Issues that are triaged by dev team and are in investigation. and removed 🆕 Triage Needed For new issues, not triaged yet. labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug! Issues that are bugs in the drivers we maintain. ✔️ Triage Done Issues that are triaged by dev team and are in investigation.
Projects
None yet
Development

No branches or pull requests

2 participants