dotnet / SqlClient

Microsoft.Data.SqlClient provides database connectivity to SQL Server for .NET applications.
MIT License
854 stars 286 forks source link

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

Open mbakalov opened 3 years ago

mbakalov commented 3 years ago

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: https://github.com/dotnet/SqlClient/issues/441

cheenamalhotra commented 3 years ago

Hi @mbakalov

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

mbakalov commented 3 years ago

@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!

Tony322 commented 3 years ago

I can confirm. I have the exact same issue.

ldsenow commented 3 years ago

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

poychang commented 3 years ago

@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.

kfrancis commented 2 years ago

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

luizgrs commented 2 years ago

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

kfrancis commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

Scott-VentsUS commented 2 years ago

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

lcheunglci commented 2 years ago

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.

lcheunglci commented 2 years ago

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

juanii commented 10 months ago

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?

HolisticDeveloper commented 9 months ago

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

luiz-soares commented 9 months ago

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>