You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Microsoft.Data.SqlClient.SNI not deployed to _PublishedWebsites for an ASP.NET Web Application #936
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.
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.
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!
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.
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?
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.
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 -->
<ImportProject="..\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 -->
<TargetName="_CopySNIWebApplicationLegacy"AfterTargets="CopySNIFiles"Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'">
<CopySourceFiles="@(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:
<TargetName="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. -->
<CopySourceFiles="@(SNIFiles)"DestinationFiles="@(SNIFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
<TargetName="_CopySNIWebApplicationLegacy"AfterTargets="CopySNIFiles"Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'">
<CopySourceFiles="@(SNIFiles)"DestinationFiles="@(SNIFiles -> '$(WebProjectOutputDir)\bin\%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>
Hopefully, there will be an updated .targets file in the next release?
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
Assign this issue to Copilot coding agent to investigate incorporating the community-proposed fix into Microsoft.Data.SqlClient.SNI.targets (the packaging project that emits this targets file, not src/Microsoft.Data.SqlClient/src/): add an AfterTargets="CopySNIFiles" (or equivalent) target, conditioned on '$(WebProjectOutputDir)' != '', that copies @(SNIFiles) into $(WebProjectOutputDir)in\%(RecursiveDir)%(Filename)%(Extension), mirroring the conditional logic used by _CopyWebApplicationLegacy in Microsoft.WebApplication.targets.
Since this is tracked under the parent epic SNI loading issues #4129 ("SNI loading issues"), coordinate the fix with that broader initiative to avoid duplicate work.
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.
Activity
cheenamalhotra commentedon Feb 26, 2021
Hi @mbakalov
Thanks for the repro. We'll investigate and get back to you soon!
mbakalov commentedon Feb 26, 2021
@cheenamalhotra - thank you for a quick response!
I'd worked around this for now by adding the below target to my webapp.csproj:
It works well enough for my scenario, but looking into the
Microsoft.WebApplication.targetsfile, the correct fix is probably much more complicated.Thanks again!
Tony322 commentedon Jun 22, 2021
I can confirm. I have the exact same issue.
ldsenow commentedon Aug 26, 2021
WOW, I experience the same issue and tried the work around mentioned above and it didnt work. Any tips?
poychang commentedon Oct 1, 2021
This workaround works for me.
Hoping has non-workaround fix soon.
kfrancis commentedon Dec 9, 2021
For some reason, this is really biting me now. A number of production pushes now have resulted in failures due to this.
luizgrs commentedon Apr 11, 2022
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:
Lines above doesn't exist in VS2022 build logs.
Any updates @cheenamalhotra ?
Thanks
kfrancis commentedon Apr 12, 2022
I did find this, and it's at least helped with the situation where IIS express can't deploy because of locked files.
Scott-VentsUS commentedon Oct 4, 2022
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!
lcheunglci commentedon Oct 4, 2022
The experience is better in newer versions of Microsoft.Data.SqlClient. Try something newer than 1.x.
Scott-VentsUS commentedon Oct 4, 2022
I updated to Microsoft.Data.SqlClient 5.0.0 and Microsoft.Data.SqlClient.SNI 5.0.0 and still the same issue
lcheunglci commentedon Oct 4, 2022
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.1to4.6.2since M.D.S 5.0 only support 4.6.2 and above and ran themsbuild /t:Build /p:Configuration=Release /p:Platform="Any CPU" Example.sln /p:OutDir=C:\temp\outputand the SNI.dlls (i.e.Microsoft.Data.SqlClient.SNI.x64.dll,Microsoft.Data.SqlClient.SNI.x86.dlland along with their pdbs) were copied into the output folder.lcheunglci commentedon Oct 11, 2022
@Scott-VentsUS are you able to provide a different repro sample as the one provided from the original author works fine.
juanii commentedon Jan 11, 2024
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\binsubdirectory. Do you mean that location in your comment?HolisticDeveloper commentedon Jan 31, 2024
@cheenamalhotra any progress on this issue? Are you waiting for anything?
luiz-soares commentedon Feb 7, 2024
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:
smaglio81 commentedon Nov 20, 2024
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
_CopyWebApplicationLegacytarget runs beforeCopySNIFiles, and that none of the SNI specific files are copied into the_PublishedWebsitesfolder.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
_CopyWebApplicationLegacyinMicrosoft.WebApplication.targetsand that seemed to be a working fix.I placed it the
.csprojfile just below the<Import>ofMicrosoft.Data.SqlClient.SNI.targets:Possible Fix
Adding mbakalov's workaround, to
Microsoft.Data.SqlClient.SNI.targetsseems to fix the issue.I was unable to find
Microsoft.Data.SqlClient.SNI.targetswithin 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:Hopefully, there will be an updated
.targetsfile in the next release?priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
🔍 Triage Summary (on-demand re-triage)
Area\Native SNIAnalysis
This is a long-standing MSBuild/packaging issue: the
Microsoft.Data.SqlClient.SNInative targets file does not copy the SNI native binaries into the_PublishedWebsites\<WebApp>infolder 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 theCopySNIFiles-style target inMicrosoft.Data.SqlClient.SNI.targetsruns independently of (and possibly before) the_CopyWebApplicationLegacy/CopyAllFilesToSingleFolderForPackagetargets defined inMicrosoft.WebApplication.targets, so files copied to the intermediateOutDirnever get propagated into the nested_PublishedWebsitesoutput. Multiple community members have confirmed reproduction as recently asMicrosoft.Data.SqlClient 5.2.2with VS2022, and a workingAfterTargets="CopySNIFiles"MSBuild workaround has been shared and refined over time (most recently by@smaglio81in 2024-11-20, proposing the fix be baked directly intoMicrosoft.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
Microsoft.Data.SqlClient.SNI.targets(the packaging project that emits this targets file, notsrc/Microsoft.Data.SqlClient/src/): add anAfterTargets="CopySNIFiles"(or equivalent) target, conditioned on'$(WebProjectOutputDir)' != '', that copies@(SNIFiles)into$(WebProjectOutputDir)in\%(RecursiveDir)%(Filename)%(Extension), mirroring the conditional logic used by_CopyWebApplicationLegacyinMicrosoft.WebApplication.targets.msbuild /p:OutDir=...) and modern VS2022 publish flows, onnet462+ targets.