Skip to content

Microsoft.Data.SqlClient.SNI not deployed to _PublishedWebsites for an ASP.NET Web Application #936

Open

Description

@mbakalov

Background

For ASP.NET Web Applications it is common to build them providing /p:OutDir=someDir (or /p:OutputPath=someDir) parameter and then taking the _PublishedWebsites\WebApp contents and xcopy-ing them.

The custom SNI-deploying targets do support OutDir but not for a web app scenario - the SNI .dlls don't get copied to _PublishedWebsites\WebApp\bin.

Steps to reproduce

A repo with a blank ASP.NET Web App and steps to reproduce: https://github.com/mbakalov/SqlClientSniRepro1

To reproduce, in VS command prompt do:

msbuild /t:Build /p:Configuration=Release /p:Platform="Any CPU" Example.sln /p:OutDir=C:\temp\output

The SNI .dlls get copied to C:\temp\output, but not to C:\Temp\output\_PublishedWebsites\WebApp\bin

Expected behavior

Expected the SNI .dlls to be copied to the "bin" folder of the published website.

Further technical details

Microsoft.Data.SqlClient version: 2.1.1
.NET target: net461

Related issue: #441

Activity

  1. cheenamalhotra commented on Feb 26, 2021

    @cheenamalhotra
    Member

    Hi @mbakalov

    Thanks for the repro. We'll investigate and get back to you soon!

  2. mbakalov commented on Feb 26, 2021

    @mbakalov
    MemberAuthor

    @cheenamalhotra - thank you for a quick response!

    I'd worked around this for now by adding the below target to my webapp.csproj:

    <Target Name="_CopySNIFilesToWebProjectOutputDir"
            AfterTargets="CopySNIFiles"
            Condition="'$(WebProjectOutputDir)' != ''">
    		
    	<Copy SourceFiles="@(SNIFiles)"
    	      DestinationFiles="@(SNIFiles -> '$(WebProjectOutputDir)\bin\%(RecursiveDir)%(Filename)%(Extension)')"/>
    </Target>

    It works well enough for my scenario, but looking into the Microsoft.WebApplication.targets file, the correct fix is probably much more complicated.

    Thanks again!

  3. added
    Area\Native SNI
    on Mar 1, 2021
  4. Tony322 commented on Jun 22, 2021

    @Tony322

    I can confirm. I have the exact same issue.

  5. ldsenow commented on Aug 26, 2021

    @ldsenow

    WOW, I experience the same issue and tried the work around mentioned above and it didnt work. Any tips?

  6. poychang commented on Oct 1, 2021

    @poychang

    @cheenamalhotra - thank you for a quick response!

    I'd worked around this for now by adding the below target to my webapp.csproj:

    <Target Name="_CopySNIFilesToWebProjectOutputDir"
            AfterTargets="CopySNIFiles"
            Condition="'$(WebProjectOutputDir)' != ''">
    		
    	<Copy SourceFiles="@(SNIFiles)"
    	      DestinationFiles="@(SNIFiles -> '$(WebProjectOutputDir)\bin\%(RecursiveDir)%(Filename)%(Extension)')"/>
    </Target>
    

    It works well enough for my scenario, but looking into the Microsoft.WebApplication.targets file, the correct fix is probably much more complicated.

    Thanks again!

    This workaround works for me.
    Hoping has non-workaround fix soon.

  7. kfrancis commented on Dec 9, 2021

    @kfrancis

    For some reason, this is really biting me now. A number of production pushes now have resulted in failures due to this.

  8. luizgrs commented on Apr 11, 2022

    @luizgrs

    The problem occurs when using VS2022 (msbuild 17) to publish Web Applications using any version of Microsoft.Data.SqlClient, the files are not copied to OBJ folder and then not copied to final target folder.

    If using VS2019 it works fine, in VS2019 build log we can see:

    CopyAllFilesToSingleFolderForPackage:
      Creating directory "obj\Release\Package\PackageTmp".
      Copying all files to temporary location below for package/publish:
      obj\Release\Package\PackageTmp.
      Copying D:\362\s\packages\Microsoft.Data.SqlClient.SNI.1.0.19235.1\build\net46\x64\SNI.dll to obj\Release\Package\PackageTmp\bin\x64\SNI.dll.
      Copying D:\362\s\packages\Microsoft.Data.SqlClient.SNI.1.0.19235.1\build\net46\x64\SNI.pdb to obj\Release\Package\PackageTmp\bin\x64\SNI.pdb.
      Copying D:\362\s\packages\Microsoft.Data.SqlClient.SNI.1.0.19235.1\build\net46\x86\SNI.dll to obj\Release\Package\PackageTmp\bin\x86\SNI.dll.
      Copying D:\362\s\packages\Microsoft.Data.SqlClient.SNI.1.0.19235.1\build\net46\x86\SNI.pdb to obj\Release\Package\PackageTmp\bin\x86\SNI.pdb.
    

    Lines above doesn't exist in VS2022 build logs.

    Any updates @cheenamalhotra ?

    Thanks

  9. kfrancis commented on Apr 12, 2022

    @kfrancis

    I did find this, and it's at least helped with the situation where IIS express can't deploy because of locked files.

  10. Scott-VentsUS commented on Oct 4, 2022

    @Scott-VentsUS

    Any update on this? @poychang 's workaround is not working. The only way I can get it to work is on each device after install, to manually copy and paste the x64 and x86 folders with SNI inside it from the debug in the project files to the application folder "C:\Users\Scott\AppData\Local\Apps\2.0\KD9YXEPJ.DKY\5QCR3OCQ.WRY\vent..tion_098ef6a925fa6387_0001.0009_35951381a6b516d2"

    for each machine. I need to install this program often enough for this to be a hassle.
    Any idea how I can streamline it better or find another workaround?
    Thanks!

  11. lcheunglci commented on Oct 4, 2022

    @lcheunglci
    Contributor

    The experience is better in newer versions of Microsoft.Data.SqlClient. Try something newer than 1.x.

  12. Scott-VentsUS commented on Oct 4, 2022

    @Scott-VentsUS

    The experience is better in newer versions of Microsoft.Data.SqlClient. Try something newer than 1.x.

    I updated to Microsoft.Data.SqlClient 5.0.0 and Microsoft.Data.SqlClient.SNI 5.0.0 and still the same issue

  13. lcheunglci commented on Oct 4, 2022

    @lcheunglci
    Contributor

    The experience is better in newer versions of Microsoft.Data.SqlClient. Try something newer than 1.x.

    I updated to Microsoft.Data.SqlClient 5.0.0 and Microsoft.Data.SqlClient.SNI 5.0.0 and still the same issue

    I just ran the sample repro project from the original author of this post https://github.com/mbakalov/SqlClientSniRepro1 and upgrade the project from .NET Framework 4.6.1 to 4.6.2 since M.D.S 5.0 only support 4.6.2 and above and ran the
    msbuild /t:Build /p:Configuration=Release /p:Platform="Any CPU" Example.sln /p:OutDir=C:\temp\output and the SNI.dlls (i.e. Microsoft.Data.SqlClient.SNI.x64.dll, Microsoft.Data.SqlClient.SNI.x86.dll and along with their pdbs) were copied into the output folder.

  14. lcheunglci commented on Oct 11, 2022

    @lcheunglci
    Contributor

    @Scott-VentsUS are you able to provide a different repro sample as the one provided from the original author works fine.

  15. juanii commented on Jan 11, 2024

    @juanii

    Just came across this issue and I can still reproduce it using the reproduction repo and the VS2022 build toolchain.
    @lcheunglci I can see the files are copied to the build output folder as you mention, but the OP stated that they were actually copied there, they're missing from the published website folder though, in the _PublishedWebsites\WebApp\bin subdirectory. Do you mean that location in your comment?

  16. HolisticDeveloper commented on Jan 31, 2024

    @HolisticDeveloper

    @cheenamalhotra any progress on this issue? Are you waiting for anything?

  17. luiz-soares commented on Feb 7, 2024

    @luiz-soares

    Since v2, such files are not copied to folders x64/x86 anymore but directly into bin instead.

    So if you are upgrading v1, try the app instead of just checking if such folders were created. I have successfully upgraded to v5.

    It worth checking breaking changes in that link.

    If sticking to v1, this workaround should get files copied:

      <Target Name="_CopySNIFilesForPublishPackage"
            AfterTargets="CopyAllFilesToSingleFolderForPackage">
    
        <Copy SourceFiles="@(SNIFiles)"
              DestinationFiles="@(SNIFiles -> '$(_PackageTempDir)\bin\%(RecursiveDir)%(Filename)%(Extension)')"/>
      </Target>
    
  18. smaglio81 commented on Nov 20, 2024

    @smaglio81

    Hello,

    This issue seems to be recurring (continuing to occur?) with VS 2022 & Microsoft.Data.SqlClient 5.2.2 / Microsoft.Data.SqlClient.SNI 5.2.0.

    I've cloned mbakalov's original repo and updated it to net48 and Microsoft.Data.SqlClient 5.2.2, https://github.com/smaglio81/SqlClientSniRepro1

    The output-reproduction.log shows the _CopyWebApplicationLegacy target runs before CopySNIFiles, and that none of the SNI specific files are copied into the _PublishedWebsites folder.

    Work Around

    It looks like mbakalov's original workaround is still very relevant. Unfortunately, luiz-soares's did not work for me.

    I updated mbakalov's original workaround to use the Conditional statement from _CopyWebApplicationLegacy in Microsoft.WebApplication.targets and that seemed to be a working fix.

    I placed it the .csproj file just below the <Import> of Microsoft.Data.SqlClient.SNI.targets:

      <!-- for people trying to implement the workaround, the Import line will already exist in your .csrpoj file -->
      <Import Project="..\packages\Microsoft.Data.SqlClient.SNI.5.2.0\build\net462\Microsoft.Data.SqlClient.SNI.targets" Condition="Exists('..\packages\Microsoft.Data.SqlClient.SNI.5.2.0\build\net462\Microsoft.Data.SqlClient.SNI.targets')" />
    
      <!-- add this Target after the Import -->
      <Target Name="_CopySNIWebApplicationLegacy"
            AfterTargets="CopySNIFiles" 
            Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'">
    
        <Copy SourceFiles="@(SNIFiles)"
              DestinationFiles="@(SNIFiles -> '$(WebProjectOutputDir)\bin\%(RecursiveDir)%(Filename)%(Extension)')"/>
      </Target>

    Possible Fix

    Adding mbakalov's workaround, to Microsoft.Data.SqlClient.SNI.targets seems to fix the issue.

    I was unable to find Microsoft.Data.SqlClient.SNI.targets within this source control repository so I haven't been able to create a pull request with the update (sorry).

    Example update to Microsoft.Data.SqlClient.SNI.targets:

      <Target Name="CopySNIFiles"
              Condition="'$(CopySNIFiles)' != 'false' And
                         '$(OutDir)' != '' And
                         HasTrailingSlash('$(OutDir)') And
                         Exists('$(OutDir)')"
              Inputs="@(SNIFiles)"
              Outputs="@(SNIFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')">
        <!--
            NOTE: Copy "Microsoft.Data.SqlClient.SNI.dll" and all related files, for every
                  architecture that we support, to the build output directory.        
        -->
        <Copy SourceFiles="@(SNIFiles)"
              DestinationFiles="@(SNIFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
      </Target>
    
      <Target Name="_CopySNIWebApplicationLegacy"
            AfterTargets="CopySNIFiles" 
            Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'">
    
        <Copy SourceFiles="@(SNIFiles)"
              DestinationFiles="@(SNIFiles -> '$(WebProjectOutputDir)\bin\%(RecursiveDir)%(Filename)%(Extension)')"/>
      </Target>

    Hopefully, there will be an updated .targets file in the next release?

  19. moved this from To triage to Backlog in SqlClient Boardon Jan 10, 2026
  20. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

  21. github-actions commented on Sep 17, 2026

    @github-actions

    🔍 Triage Summary (on-demand re-triage)

    Check Result
    Issue type Bug
    Environment All required environment details provided for investigation
    Area Area\Native SNI
    Duplicates Potentially related: #441, #446, #1955 (all tracked under parent epic #4129 "SNI loading issues")
    Regression Not indicated — long-standing MSBuild/packaging issue, not a version regression

    Analysis

    This is a long-standing MSBuild/packaging issue: the Microsoft.Data.SqlClient.SNI native targets file does not copy the SNI native binaries into the _PublishedWebsites\<WebApp>in folder when building an ASP.NET Web Application with /p:OutDir=... (the classic "web deployment" publish flow used since VS2019/2022). The root cause is that the CopySNIFiles-style target in Microsoft.Data.SqlClient.SNI.targets runs independently of (and possibly before) the _CopyWebApplicationLegacy/CopyAllFilesToSingleFolderForPackage targets defined in Microsoft.WebApplication.targets, so files copied to the intermediate OutDir never get propagated into the nested _PublishedWebsites output. Multiple community members have confirmed reproduction as recently as Microsoft.Data.SqlClient 5.2.2 with VS2022, and a working AfterTargets="CopySNIFiles" MSBuild workaround has been shared and refined over time (most recently by @smaglio81 in 2024-11-20, proposing the fix be baked directly into Microsoft.Data.SqlClient.SNI.targets). Given the multi-year recurrence, breadth of affected users (ASP.NET Web Application publish scenarios), and existence of a known, low-risk community-validated workaround, this is a P2 engineering/packaging fix — non-blocking (workaround exists) but worth resolving upstream since it repeatedly affects new users of the legacy ASP.NET Web Application publish model.

    Next Steps

    Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.

    Generated by SqlClient Issue Auto-Triage for #936 · copilot · auto · 68.2 AIC · ⌖ 13.2 AIC · ⊞ 11.9K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area\Native SNI

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions