내 WPF 프로그램에서 사용되는 범용 유틸리티 DLL 파일이 있습니다. 내 프로그램이하는 첫 번째 일은 업데이트 된 dll 파일을 확인하고 dll의 메소드 나 속성을 참조하지 않고 실행중인 디렉토리에 복사합니다.Visual Studio에서 EXE 파일과 DLL로드 시간이 다른 경우
Visual Studio (v10)에서 프로그램을 컴파일하고 실행하면 모든 것이 예상대로 작동합니다. 프로그램이 시작되고 dll 파일을 검사하고 필요한 경우 복사 한 다음 어셈블리 사용을 계속합니다.
Windows 탐색기에서 컴파일 된 .exe 파일을 실행하면 가장 먼저 Util.dll 어셈블리를로드하는 것 같습니다. 이렇게하면 파일이 잠기므로 파일을 업데이트 할 수 없습니다.
누구나 프로그램이 Visual Studio에서 .exe 파일과 다른 이유는 무엇인지에 대한 통찰력이 있습니까? .exe 파일을 실행할 때 어셈블리가로드되는 원인을 추적하는 방법에 대한 의견이 있으십니까? 파일이 복사되는
void AppLoad(object sender, StartupEventArgs e)
{
//Used to see what assemblies are loaded.
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var item in AppDomain.CurrentDomain.GetAssemblies())
{
sb.AppendLine(item.FullName.ToString());
}
System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "test.txt", sb.ToString());
//Check for the latest Util dll.
if (!UpdateUtil())
{
//Shutdown.
Application.Current.Shutdown();
return;
}
//Start the main window.
MainWindow m = new MainWindow();
m.Show();
}
bool UpdateUtil()
{
//Verify network path.
if (!Directory.Exists(_componentPath))
{
MessageBox.Show("The program encountered an error.\r\rPlease contact your Program Administrator with the following information:\r\r" +
"Program Name - Genesis Admin\r\r" +
"Error Message - Network Component path not found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}
//Verify file existance.
string sourceFileName = _componentPath + "Util.dll";
if (!File.Exists(sourceFileName))
{
MessageBox.Show("The program encountered an error.\r\rPlease contact your Program Administrator with the following information:\r\r" +
"Program Name - Genesis Admin\r\r" +
"Error Message - Network Util file not found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}
string destFileName = AppDomain.CurrentDomain.BaseDirectory + "Util.dll";
if (!File.Exists(destFileName) || File.GetLastWriteTime(sourceFileName) > File.GetLastWriteTime(destFileName))
File.Copy(sourceFileName, destFileName, true);
return true;
}
FYI 이것은 대부분의 IT 관리자가이 방법을 사용하지 않을 경우 (매우 안전하지 않음) 실제 프로덕션 환경에서는 작동하지 않습니다. – tsells