【发布时间】:2021-11-19 03:10:32
【问题描述】:
我正在尝试在 IIS 中使用 EFCore 3.1.16 解决 ASP.Net Framework 4.8 站点的问题。 Microsoft.Data.SqlClient 在 SNI.dll 上有一个进程锁定,这会导致 IIS 中的 xcopy 部署出现问题。
我尝试了将 SNI.dll 复制到与 Microsoft.Data.SqlClient 相同的卷影副本位置的策略,因此它不必尝试访问 bin 文件夹中的 DLL,如https://github.com/lscorcia/sqlclient.snishadowcopy 中所述。
// Look for the main Microsoft.Data.SqlClient assembly in the
// shadow copy path
var sqlClientShadowAssembly = Directory.GetFiles(
currentShadowPath, "Microsoft.Data.SqlClient.dll",
SearchOption.AllDirectories).FirstOrDefault();
// Extract the directory information from the shadow assembly path
var sqlClientShadowPath =
Path.GetDirectoryName(sqlClientShadowAssembly);
// Find out the process bitness and choose the appropriate native
// assembly
var moduleName = Environment.Is64BitProcess ? "x86\\SNI.dll"
: "x64\\SNI.dll";
// Compute the source and target paths for the native assembly
var sourceFile = Path.Combine(currentPrivatePath, moduleName);
var targetFile = Path.Combine(sqlClientShadowPath, "SNI.dll");
File.Copy(sourceFile, targetFile);
但是,它仍然会首先尝试访问 bin 位置,而不是位于同一文件夹位置的 sni.dll。
我已通过删除 DLL 并确认引发 FileNotFound 异常来检查影子位置中的 Microsoft.Data.SqlClient 是否正确使用。我还尝试直接复制到同一个文件夹并复制到 x64阴影位置中的子文件夹。
【问题讨论】:
-
升级到 .NET 6 然后就可以使用真正的卷影副本docs.microsoft.com/en-us/aspnet/core/release-notes/…
-
你用的是什么应用程序?如果是 asp.net 应用程序,IIS 不会在进程运行时阻止 dll 文件。如果是asp.net核心应用,需要升级到.net 6。
标签: asp.net iis xcopy ef-core-3.1 shadow-copy