MEF를 사용하여 어셈블리를로드하는 WinForms 프로그램을 작성하고 있습니다. 이러한 어셈블리는 실행 파일과 같은 폴더에 있지 않습니다. 파일 유지 관리를 수행해야하므로 실제 WinForm을로드하기 전에 Program.cs 파일에 일부 코드를 구현하여 파일 (어셈블리 인 경우에도)이 프로그램에서로드되지 않도록해야합니다. .파일 조작으로 파일 블록 처리
내가이 작업을 수행하고 있습니다 : - 타 하나 개 한 위치에서 폴더를 이동 - 아카이브에서 파일 인 경우 폴더에서 dll 파일을 아카이브에서 압축 풀기 파일 덮어 쓰기 이동 (것보다 새로운 이동)
폴더를 이동 한 후에 파일이 잠겨 덮어 쓸 수 없다는 것이 문제입니다. 또한 이동이 끝나면 파일을 하나씩 이동하여 파일을 이동하려고했습니다.
는 누군가가 파일이 차단 된 이유를 나에게 설명 할 수 나는
감사
private static void InitializePluginsFolder()
{
if (!Directory.Exists(Paths.PluginsPath))
{
Directory.CreateDirectory(Paths.PluginsPath);
}
// Find archive that contains plugins to deploy
var assembly = Assembly.GetExecutingAssembly();
if (assembly.Location == null)
{
throw new NullReferenceException("Executing assembly is null!");
}
var currentDirectory = new FileInfo(assembly.Location).DirectoryName;
if (currentDirectory == null)
{
throw new NullReferenceException("Current folder is null!");
}
// Check if previous installation contains a "Plugins" folder
var currentPluginsPath = Path.Combine(currentDirectory, "Plugins");
if (Directory.Exists(currentPluginsPath))
{
foreach (FileInfo fi in new DirectoryInfo(currentPluginsPath).GetFiles())
{
using (FileStream sourceStream = new FileStream(fi.FullName, FileMode.Open))
{
using (FileStream destStream = new FileStream(Path.Combine(Paths.PluginsPath, fi.Name), FileMode.Create))
{
destStream.Lock(0, sourceStream.Length);
sourceStream.CopyTo(destStream);
}
}
}
Directory.Delete(currentPluginsPath, true);
}
// Then updates plugins with latest version of plugins (zipped)
var pluginsZipFilePath = Path.Combine(currentDirectory, "Plugins.zip");
// Extract content of plugins archive to a temporary folder
var tempPath = string.Format("{0}_Temp", Paths.PluginsPath);
if (Directory.Exists(tempPath))
{
Directory.Delete(tempPath, true);
}
ZipFile.ExtractToDirectory(pluginsZipFilePath, tempPath);
// Moves all plugins to appropriate folder if version is greater
// to the version in place
foreach (var fi in new DirectoryInfo(tempPath).GetFiles())
{
if (fi.Extension.ToLower() != ".dll")
{
continue;
}
var targetFile = Path.Combine(Paths.PluginsPath, fi.Name);
if (File.Exists(targetFile))
{
if (fi.GetAssemblyVersion() > new FileInfo(targetFile).GetAssemblyVersion())
{
// If version to deploy is newer than current version
// Delete current version and copy the new one
// FAILS HERE
File.Copy(fi.FullName, targetFile, true);
}
}
else
{
File.Move(fi.FullName, targetFile);
}
}
// Delete temporary folder
Directory.Delete(tempPath, true);
}
코드를 공유하십시오. –
슬프게도 우리는 실제로 그것으로부터 추측 할 수 없습니다. – BugFinder
죄송합니다. 많은 코드를 넣고 싶지는 않지만 확실히 도움이 될 것 같습니다. 이 메서드는 Main 메서드에서 호출 된 첫 번째 메서드입니다. –