클릭원스를 이용한 dll 자동다운로드
http://msdn.microsoft.com/ko-kr/library/ak58kz04.aspx
[클릭원스 배포시 프로젝트(dll)을 필요 시 다운로드 하는 방법]
모듈A
부모프로젝트
[작성방법]
1.우선 모듈A를 참조한다
2.그리고 배포시 부모프로젝트에서 모듈A를 빼고 배포한다 (제외(?))시키는 방법은 아래 참고
모듈A를 include하고 다운로드 그룹 이름을 지정한다
추후에 다운 받을 때 다운로드 그룹 이름을 이용해서 다운받는다
[부모프로젝트에서 모듈A를 요청할때 ]
Dictionary<String, String> DllMapping = new Dictionary<String, String>();
private int childFormNumber = 0;
public MDIParent1()
{
InitializeComponent();
DllMapping["ClickOnceLibrary"] = "ClickOnceLibrary";
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
//클릭이벤트 여기서 호출
private void toolStripButton4_Click(object sender, EventArgs e)
{
try
{
Insa_module.TestClass dc = new Insa_module.TestClass();
Insa_module.Insa2 insa = new Insa_module.Insa2();
insa.Show();
MessageBox.Show("Message: " + dc.Message);
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
/*
* Use ClickOnce APIs to download the assembly on demand.
*/
Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
Assembly newAssembly = null;
if (ApplicationDeployment.IsNetworkDeployed)
{
ApplicationDeployment deploy = ApplicationDeployment.CurrentDeployment;
// Get the DLL name from the Name argument.
string[] nameParts = args.Name.Split(',');
string dllName = nameParts[0];
string downloadGroupName = DllMapping[dllName];
try
{
deploy.DownloadFileGroup(downloadGroupName);
}
catch (DeploymentException de)
{
MessageBox.Show("Downloading file group failed. Group name: " + downloadGroupName + "; DLL name: " + args.Name);
throw (de);
}
// Load the assembly.
// Assembly.Load() doesn't work here, as the previous failure to load the assembly
// is cached by the CLR. LoadFrom() is not recommended. Use LoadFile() instead.
try
{
newAssembly = Assembly.LoadFile(Application.StartupPath + @"\" + dllName + ".dll");
}
catch (Exception e)
{
throw (e);
}
}
else
{
//Major error - not running under ClickOnce, but missing assembly. Don't know how to recover.
throw (new Exception("Cannot load assemblies dynamically - application is not deployed using ClickOnce."));
}
return (newAssembly);
}
}