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

Improve SNI package architecture and targets file design #2998

Open
jzabroski opened this issue Nov 12, 2024 · 22 comments
Open

Improve SNI package architecture and targets file design #2998

jzabroski opened this issue Nov 12, 2024 · 22 comments
Labels
Area\Native SNI Issues that are targeted to the Native SNI codebase. 💡 Enhancement Issues that are feature requests for the drivers we maintain. ✔️ Triage Done Issues that are triaged by dev team and are in investigation.

Comments

@jzabroski
Copy link

jzabroski commented Nov 12, 2024

I am pulling my hair out trying to figure out why SNI.x64.dll isn't getting copied to my output directory on build.

i believe the issue has something to do with x86 vs x64 wow process virtualization, but I don't know how to prove it. Our TeamCity account runs as a MSA Group Principal DOMAINNAME\msaTeamCity$ and that users package cache is C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\

When I use msbuild binlogging, I see CopySNIFiles silently fails

20241112_153410.jpg

  1. After CopySNIFiles runs, can anything blow it away?
  2. Why would this work on the same machine as a different user?
  3. Would using the new dotnet 8 artifacts path solve this problem?

I think this is probably the root cause of a litter of issues people have, although I suspect there is even more that can be cleaned up here. Such discussion is probably best saved for a WhatsApp or Discord voice call.

@jzabroski
Copy link
Author

I have tried directly referencing Microsoft.Data.SqlClient and separately Microsoft.Data.SqlClient.SNI and neither one gets copied.

CopySNIFiles doesn't get run when running under a MSA Group account. I don't understand why, although I also really doubt i would have written the SNI.targets file this way.

@jzabroski
Copy link
Author

The issue seems to be that, when running on the build server, OutDir has a different value, which includes the TargetFramework.

We have a csproj with:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <AppendTargetFrameworkToOutputPath>false<AppendTargetFrameworkToOutputPath>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
  </PropertyGroup>

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

This results in OutDir evaluating to bin\Release\net48 but ONLY due to SNI targets getting evaluated at restore time, which apparently somehow ignores the above AppendX properties.

@jzabroski
Copy link
Author

jzabroski commented Nov 13, 2024

@ErikEJ Why doesn't Microsoft.Data.SqlClient.SNI package things the way Microsoft recommends as best practice? https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks and https://learn.microsoft.com/en-us/nuget/create-packages/native-files-in-net-packages#native-assets

In comparing what your team is doing to what Grpc.Core does , they seem to be exactly following the best practices, and I don't run into any issues using their library.

I actually can't find where Microsoft.Data.SqlClient.SNI.targets is defined in this repository, so I can't even submit a PR to rewrite the thing to follow best practices.

@cheenamalhotra
Copy link
Member

@jzabroski

I tested your csproj in a standalone project and I don't face any issues, and SNI files are being copied in output folder alongside other binaries as expected. You must note the 'buildTransitive' folder is where the files will be copied from in this case.

Image

[Please open the child Task in your screenshot, you should find this IMO]

Using buildTransitive folder is the recommended way for Native dependencies (ref: Native files in .NET packages) and targets file is definitely loaded otherwise the target 'CopySNIFiles' wouldn't be running in your env.

The issue seems to be that, when running on the build server, OutDir has a different value, which includes the TargetFramework.

Why is this the case in your build server? Are you modifying it manually?

@cheenamalhotra cheenamalhotra added the ✔️ Triage Done Issues that are triaged by dev team and are in investigation. label Nov 13, 2024
@jzabroski
Copy link
Author

The project runs fine, on the build server, with me as the user.

When run as a MSA Group Principal (passwordless login managed by Active Directory), it does not copy the files for some reason.

I want to emphasize, I do NOT run into this problem with Grpc.Core, and i do NOT see issues in the Grpc.Core library related to native dlls not loading correctly. This repository has more issues than I can count with loading SNI.dll. I think it is time to rethink the approach.

@jzabroski
Copy link
Author

See also dotnet/msbuild#10973

@cheenamalhotra
Copy link
Member

Thanks to the reference to Grpc.Core and I like that it's neat.

Our design of MDS.SNI targets file is based on legacy systems - I agree. If's been challenging to keep up with MsBuild targets as the design we have interjects CopySNIFiles target into MsBuild process, but is clearly not 100% proof.

We will review if we can adopt a much cleaner approach without risking existing consumption.

@cheenamalhotra cheenamalhotra added the 💡 Enhancement Issues that are feature requests for the drivers we maintain. label Nov 13, 2024
@cheenamalhotra cheenamalhotra changed the title SNI package questions Improve SNI package architecture and targets file design Nov 13, 2024
@cheenamalhotra cheenamalhotra added the Area\Native SNI Issues that are targeted to the Native SNI codebase. label Nov 13, 2024
@jzabroski
Copy link
Author

To support all systems, I think there are a couple of basic scenarios.

I don't believe SNI supports Linux or Mac OSX, so there would be no folders for those.

The only issue I am not confident that would be resolved by the rewrite is the IIS shadow copy issue. I personally don't actually understand that issue, although I may have to deal with it next but doubt it as I use Octopus Deploy for IIS deployments and they have written robust logic to stop App Pools that Visual Studio right-click deploy does not do.

I am currently trying to figure out a workaround that will allow the MSA Group Principal to copy these files. Otherwise, I have to revert 120+ files related to moving from System.Data.SqlClient and stay on that for as long as it takes to resolve this issue. That is not ideal as EntityFramework 6.5.1 seems incompatible with System.Data.SqlClient (lazy loading is now broken, and @ErikEJ suggested I upgrade to Microsoft.Data.SqlClient).

@cheenamalhotra
Copy link
Member

You can include these DLLs directly in your csproj as the targets file in Grpc.Core is doing fyi, have you tried with that?

@jzabroski
Copy link
Author

jzabroski commented Nov 13, 2024

I basically tried that already. The following did not work running as a MSA Group Principal but did work locally.

<Project Sdk="Microsoft.NET.Sdk">
  <!-- ReSharper disable UnknownProperty -->
  <PropertyGroup>
    <AssemblyTitle>Weiss.Panda.TaskRunner</AssemblyTitle>
    <TargetFramework>net48</TargetFramework>
    <OutputType>Exe</OutputType>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    <CopySNIFiles>false</CopySNIFiles> <!-- THIS IS WHERE I DISABLE the SNI.targets BEHAVIOR -->
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Data.SqlClient.SNI" Version="5.2.0" GeneratePathProperty="true" />
  </ItemGroup>

  <Target Name="SNITest" AfterTargets="CopySNIFiles">
    <Message Text="Files: @(SNIFiles)" />
    <Message Text="DLL Files: @(SNIDllFiles)" />
  </Target>

  <ItemGroup>
    <None Include="$(PkgMicrosoft_Data_SqlClient_SNI)\buildTransitive\net462\*"
          Exclude="$(PkgMicrosoft_Data_SqlClient_SNI)\buildTransitive\net462\*.targets"
          CopyToOutputDirectory="PreserveNewest"
          Pack="true"
          PackagePath="" />
  </ItemGroup>
</Project>

This produces the following trace in binlog:

Image

If I also search for the phrase, Copying file from "C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\buildTransitive\net462\microsoft.data.sqlclient.SNI.x64.dll , I can see MSBuild reports the copy as completed as well. But it does not actually occur.

@cheenamalhotra
Copy link
Member

I still don't understand what exactly are you doing with the MSA Group Principal (I'm not familiar with what its used for), is it a build or publish step that is not working?

@jzabroski
Copy link
Author

jzabroski commented Nov 13, 2024

The problem occurs on build.

An MSA Group Principal is just a special account that has no password. You simply tell your Active Directory Domain Controller that a specific Machine SID is associated with a particular account, and that account is a principal on that Machine SID. Once they become linked, you no longer need a password to login. From a cybersecurity policy perspective, this is preferred to running as NT AUTHORITY\System as it can have less trust.

We've actually been running Team City this way for about 5 years, and this is the first time I have encountered this weird issue. To say I am curious as to what the root cause is, is an understatement.

About the only conclusion I can draw from this full day of debugging is that Microsoft doesn't use MSA Group Principals to build its source code. :)

@cheenamalhotra
Copy link
Member

No, we don't as we use DevOps workflows designed to spin up environment on demand.

It seems more like an MsBuild issue to me when working with MSA accounts than ours. I hope you get the right support from them.

@jzabroski
Copy link
Author

jzabroski commented Nov 14, 2024

I can confirm that adding a PowerShell script to copy the files to some random directory on the same drive as the same behavior as your targets, so I don't actually think the failure is because of how you coded the targets succeeds, even when run as MSA account.

It seems as though there is more to this problem than just MSA accounts.

Will repeat my offer to help write .targets for this

$dest = "d:\logs\TeamCity"
$source = Join-Path $env:USERPROFILE -ChildPath ".nuget" | Join-Path -ChildPath "packages" | Join-Path -ChildPath "microsoft.data.sqlclient.sni" | Join-Path -ChildPath "5.2.0"
Write-Host $source
if (Test-Path $source) {
  # Copy all files from the source directory to the destination directory  
  $copyErrors = $null
  Copy-Item -Path "$source\*" -Destination $dest -Recurse -Force -Verbose -ErrorVariable +copyErrors
  Write-Host "Files have been copied from '$source' to '$dest'."
  Write-Host "Errors: $copyErrors"
}

Outputs:

15:14:41  PowerShell Executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
15:14:41   Working directory: D:\BuildAgent\work\77094892e16807fb
15:14:41   Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
15:14:41   PowerShell arguments: -NoProfile, -NonInteractive, -ExecutionPolicy, ByPass, -File, D:\BuildAgent\temp\buildTmp\powershell10788514782847466008.ps1
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0
15:14:41   VERBOSE: Performing the operation "Copy Directory" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\build Destination: D:\logs\TeamCity\build".
15:14:41   VERBOSE: Performing the operation "Create Directory" on target "Destination: D:\logs\TeamCity\build".
15:14:41   VERBOSE: Performing the operation "Copy Directory" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\build\net462 Destination:
15:14:41   D:\logs\TeamCity\build\net462".
15:14:41   VERBOSE: Performing the operation "Create Directory" on target "Destination: D:\logs\TeamCity\build\net462".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\build\net462\Microsoft.Data.SqlClient.SNI.arm6
15:14:41   4.dll Destination: D:\logs\TeamCity\build\net462\Microsoft.Data.SqlClient.SNI.arm64.dll".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\build\net462\Microsoft.Data.SqlClient.SNI.arm6
15:14:41   4.pdb Destination: D:\logs\TeamCity\build\net462\Microsoft.Data.SqlClient.SNI.arm64.pdb".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\build\net462\Microsoft.Data.SqlClient.SNI.targ
15:14:41   ets Destination: D:\logs\TeamCity\build\net462\Microsoft.Data.SqlClient.SNI.targets".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\build\net462\Microsoft.Data.SqlClient.SNI.x64.
15:14:41   dll Destination: D:\logs\TeamCity\build\net462\Microsoft.Data.SqlClient.SNI.x64.dll".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\build\net462\Microsoft.Data.SqlClient.SNI.x64.
15:14:41   pdb Destination: D:\logs\TeamCity\build\net462\Microsoft.Data.SqlClient.SNI.x64.pdb".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\build\net462\Microsoft.Data.SqlClient.SNI.x86.
15:14:41   dll Destination: D:\logs\TeamCity\build\net462\Microsoft.Data.SqlClient.SNI.x86.dll".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\build\net462\Microsoft.Data.SqlClient.SNI.x86.
15:14:41   pdb Destination: D:\logs\TeamCity\build\net462\Microsoft.Data.SqlClient.SNI.x86.pdb".
15:14:41   VERBOSE: Performing the operation "Copy Directory" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\buildTransitive Destination:
15:14:41   D:\logs\TeamCity\buildTransitive".
15:14:41   VERBOSE: Performing the operation "Create Directory" on target "Destination: D:\logs\TeamCity\buildTransitive".
15:14:41   VERBOSE: Performing the operation "Copy Directory" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\buildTransitive\net462 Destination:
15:14:41   D:\logs\TeamCity\buildTransitive\net462".
15:14:41   VERBOSE: Performing the operation "Create Directory" on target "Destination: D:\logs\TeamCity\buildTransitive\net462".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\buildTransitive\net462\Microsoft.Data.SqlClien
15:14:41   t.SNI.arm64.dll Destination: D:\logs\TeamCity\buildTransitive\net462\Microsoft.Data.SqlClient.SNI.arm64.dll".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\buildTransitive\net462\Microsoft.Data.SqlClien
15:14:41   t.SNI.arm64.pdb Destination: D:\logs\TeamCity\buildTransitive\net462\Microsoft.Data.SqlClient.SNI.arm64.pdb".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\buildTransitive\net462\Microsoft.Data.SqlClien
15:14:41   t.SNI.targets Destination: D:\logs\TeamCity\buildTransitive\net462\Microsoft.Data.SqlClient.SNI.targets".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\buildTransitive\net462\Microsoft.Data.SqlClien
15:14:41   t.SNI.x64.dll Destination: D:\logs\TeamCity\buildTransitive\net462\Microsoft.Data.SqlClient.SNI.x64.dll".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\buildTransitive\net462\Microsoft.Data.SqlClien
15:14:41   t.SNI.x64.pdb Destination: D:\logs\TeamCity\buildTransitive\net462\Microsoft.Data.SqlClient.SNI.x64.pdb".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\buildTransitive\net462\Microsoft.Data.SqlClien
15:14:41   t.SNI.x86.dll Destination: D:\logs\TeamCity\buildTransitive\net462\Microsoft.Data.SqlClient.SNI.x86.dll".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\buildTransitive\net462\Microsoft.Data.SqlClien
15:14:41   t.SNI.x86.pdb Destination: D:\logs\TeamCity\buildTransitive\net462\Microsoft.Data.SqlClient.SNI.x86.pdb".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\.nupkg.metadata Destination:
15:14:41   D:\logs\TeamCity\.nupkg.metadata".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\.signature.p7s Destination:
15:14:41   D:\logs\TeamCity\.signature.p7s".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\dotnet.png Destination:
15:14:41   D:\logs\TeamCity\dotnet.png".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\LICENSE.txt Destination:
15:14:41   D:\logs\TeamCity\LICENSE.txt".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\microsoft.data.sqlclient.sni.5.2.0.nupkg
15:14:41   Destination: D:\logs\TeamCity\microsoft.data.sqlclient.sni.5.2.0.nupkg".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\microsoft.data.sqlclient.sni.5.2.0.nupkg.sha51
15:14:41   2 Destination: D:\logs\TeamCity\microsoft.data.sqlclient.sni.5.2.0.nupkg.sha512".
15:14:41   VERBOSE: Performing the operation "Copy File" on target "Item:
15:14:41   C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0\microsoft.data.sqlclient.sni.nuspec
15:14:41   Destination: D:\logs\TeamCity\microsoft.data.sqlclient.sni.nuspec".
15:14:41   Files have been copied from 'C:\Users\msaTeamCity$\.nuget\packages\microsoft.data.sqlclient.sni\5.2.0' to 'd:\logs\TeamCity'.
15:14:41   Errors:
15:14:41   Process exited with code 0

@David-Engel
Copy link
Contributor

Why doesn't Microsoft.Data.SqlClient.SNI package things the way Microsoft recommends as best practice? https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks and https://learn.microsoft.com/en-us/nuget/create-packages/native-files-in-net-packages#native-assets

In comparing what your team is doing to what Grpc.Core does , they seem to be exactly following the best practices, and I don't run into any issues using their library.

I actually can't find where Microsoft.Data.SqlClient.SNI.targets is defined in this repository, so I can't even submit a PR to rewrite the thing to follow best practices.

MDS does package the recommended way when targeting .NET. The problem is you are targeting .NET Framework, which doesn't support all the new, simple packaging stuff. https://learn.microsoft.com/en-us/nuget/create-packages/native-files-in-net-packages#projects-targeting-net-framework

If you want to try improving the targets file, it's in the NuGet package: https://www.nuget.org/packages/Microsoft.Data.SqlClient.SNI/ Open the nupkg file with 7-Zip (or rename the file to .zip) and look in the buildTransitive\net462 folder. All you need to rebuild the package is a complete nuspec file. You can use this:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata minClientVersion="2.12">
    <id>Microsoft.Data.SqlClient.SNI</id>
    <version>6.0.0-preview1.24226.4</version>
    <title>Microsoft.Data.SqlClient.SNI</title>
    <authors>Microsoft</authors>
    <requireLicenseAcceptance>true</requireLicenseAcceptance>
    <license type="file">LICENSE.txt</license>
    <projectUrl>https://aka.ms/sqlclientproject</projectUrl>
    <icon>dotnet.png</icon>
    <description>
      Internal implementation package not meant for direct consumption. Please do not reference directly.

When using NuGet 3.x this package requires at least version 3.4.</description>
    <releaseNotes>https://go.microsoft.com/fwlink/?linkid=2090501</releaseNotes>
    <copyright>© Microsoft Corporation. All rights reserved.</copyright>
    <dependencies>
      <group targetFramework="net462" />
    </dependencies>
  </metadata>
  <files>
    <file src="LICENSE.txt" target="" />
    <file src="dotnet.png" target="" />
    
    <file src="build\net462\Microsoft.Data.SqlClient.SNI.dll" target="build\net462\Microsoft.Data.SqlClient.SNI.x86.dll" />
    <file src="build\net462\Microsoft.Data.SqlClient.SNI.dll" target="build\net462\Microsoft.Data.SqlClient.SNI.x64.dll" />
    <file src="build\net462\Microsoft.Data.SqlClient.SNI.dll" target="build\net462\Microsoft.Data.SqlClient.SNI.arm64.dll" />
    <file src="build\net462\Microsoft.Data.SqlClient.SNI.pdb" target="build\net462\Microsoft.Data.SqlClient.SNI.x86.pdb" />
    <file src="build\net462\Microsoft.Data.SqlClient.SNI.pdb" target="build\net462\Microsoft.Data.SqlClient.SNI.x64.pdb" />
    <file src="build\net462\Microsoft.Data.SqlClient.SNI.pdb" target="build\net462\Microsoft.Data.SqlClient.SNI.arm64.pdb" />
    <file src="build\net462\Microsoft.Data.SqlClient.SNI.targets" target="build\net462" />

    <file src="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.dll" target="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.x86.dll" />
    <file src="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.dll" target="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.x64.dll" />
    <file src="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.dll" target="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.arm64.dll" />
    <file src="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.pdb" target="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.x86.pdb" />
    <file src="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.pdb" target="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.x64.pdb" />
    <file src="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.pdb" target="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.arm64.pdb" />
    <file src="buildTransitive\net462\Microsoft.Data.SqlClient.SNI.targets" target="buildTransitive\net462" />

  </files>
</package>

Just unzip the nupkg, adjust any paths in the nuspec file (I think it will work for you as-is) and run nuget pack Microsoft.Data.SqlClient.SNI.nuspec.

@HamsterExAstris
Copy link

Does setting the MSBuild property ContentSNIFiles to true (i.e. with the MSBuild command line /p:ContentSNIFiles=true) as suggested here make any difference in your results?

@jzabroski
Copy link
Author

jzabroski commented Nov 17, 2024

@HamsterExAstris Basically yes see #2998 (comment) which is a variation... and you can see, in the msbuild binlog, that it picks up the file and says it is copied.

I should figure this out next week.

I'm going to explore the possibility there is a bug in msbuild Copy target next. I believe the number of cores my desktop has is different than the AWS m6.2xlarge we are using as a build server, so it's possible the bug is appearing when a certain number of threads copy data. I really doubt it but I have to rule that out next. It also doesn't explain why running as local administrator on the m6.2xlarge works, but maybe there is a side effect introduced by PS Remoting that implicitly limits threads somehow or something else.

@jzabroski
Copy link
Author

I'm going to try this

$dest = "d:\logs\TeamCity"
$source = Join-Path $env:USERPROFILE -ChildPath ".nuget" | Join-Path -ChildPath "packages" | Join-Path -ChildPath "microsoft.data.sqlclient.sni" | Join-Path -ChildPath "5.2.0"
Write-Host $source
if (Test-Path $source) {
  # Copy all files from the source directory to the destination directory  
  $copyErrors = $null
  Copy-Item -Path "$source\*" -Destination $dest -Recurse -Force -Verbose -ErrorVariable +copyErrors
  Write-Host "Files have been copied from '$source' to '$dest'."
  Write-Host "Errors: $copyErrors"
}

with this #2998 (comment)

#2998 (comment)

This will take MSBuild Copy target out of the picture and replace it with a

<Target Name="AfterBuild">
    <PropertyGroup>
      <PSScript> paste ps script here
      </PSScript>
    </PropertyGroup>
    <Exec Command="powershell.exe -command "$(PSScript)"" />
  </Target>

This allows me to test a linear array of assumptions about the root cause.

@jzabroski
Copy link
Author

jzabroski commented Nov 21, 2024

As a follow-up here, I believe the root cause here is that the way Microsoft.Data.SqlClient.SNI is packaged is incompatible with a clean checkout on a build due to how IncrementalClean target works in C:\Program Files\dotnet\sdk\8.0.400\Microsoft.Common.CurrentVersion.targets - it thinks these copied files are from a previous build, so it deletes them. I have not gotten to the exact reason why it thinks that, but part of the problem is potentially that these files are not included in obj/Release/<YourProjectName>.FileListAbsolute.txt

This is very likely related to #2049 (comment) and possibly other issues users have been pulling their hair out over.

@jzabroski
Copy link
Author

@David-Engel @cheenamalhotra Would it be possible to add a <FileWrites Include="@(SNIDllFiles)" /> to force these items to be tracked by the build as dependencies. It appears FileWrites is what drives FileListAbsolute.txt, and therefore should fix issues with IncrementalClean. I think if this is the issue, it would address a lot of issues this repo has received over the years.

@David-Engel
Copy link
Contributor

Would it be possible to add a <FileWrites Include="@(SNIDllFiles)" /> to force these items to be tracked by the build as dependencies. It appears FileWrites is what drives FileListAbsolute.txt, and therefore should fix issues with IncrementalClean. I think if this is the issue, it would address a lot of issues this repo has received over the years.

The easiest way to play with changes to the .targets file is to simply edit the one in your NuGet cache. Example: %USERPROFILE%\.nuget\packages\microsoft.data.sqlclient.sni\6.0.0-preview1.24226.4\buildTransitive\net462\Microsoft.Data.SqlClient.SNI.targets
(You would need to clean project-level package caches for that to propagate.)
Or if you are just working with a single test app, the one cached with that:
%USERPROFILE%\Source\repos\ConsoleAppNetFx\packages\Microsoft.Data.SqlClient.SNI.5.2.0\buildTransitive\net462\Microsoft.Data.SqlClient.SNI.targets

Once you have something that fixes your situation, share the targets file here for others to test.

@jzabroski
Copy link
Author

Did some reading tonight to see if there is an elegant path forward.

One possible thing I will try this week is explicit nuspec assembky <references> https://learn.microsoft.com/en-us/nuget/reference/nuspec#explicit-assembly-references

I'm also going to thoroughly understand why Grpc.Core doesn't give me these issues.

I do appreciate all your help, David and Cheena. Hopefully whatever I come up with makes your team job easier. However, not having the packaging in version control makes it harder to understand each incremental change as there is no audit trail on the issues that effectuate changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area\Native SNI Issues that are targeted to the Native SNI codebase. 💡 Enhancement Issues that are feature requests for 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

4 participants