나는이 사용하던 :현재 응용 프로그램 도메인에서로드 된 어셈블리 또는 참조 된 어셈블리의 이름을 가져와 C# 컴파일러에 전달하는 방법은 무엇입니까?
AppDomain.CurrentDomain.GetAssemblies().SelectMany<Assembly,string>(a => a.GetModules().Select<Module,string>(m => m.FullyQualifiedName)).ToArray()
는 모든로드 된 어셈블리의 이름을 얻을 수 있습니다.
그것은 유형에 대한 친화적 인 C#을 이름을 가져옵니다 코드에서 유래:
return (Type)(new CSharpCodeProvider().CompileAssemblyFromSource(new CompilerParameters(AppDomain.CurrentDomain.GetAssemblies().Select<Assembly,string>(a => a.CodeBase).ToArray(), null, false) {GenerateExecutable = false, GenerateInMemory = true, TreatWarningsAsErrors = false, CompilerOptions = "/optimize"}, "public static class C{public static System.Type M(){return typeof(" + friendlyName + ");}}").CompiledAssembly.GetExportedTypes()[0].GetMethod("M").Invoke(null, System.Reflection.BindingFlags.Static, null, null, null));
그러나 컴파일러과 같이 오류를 생산 : 파일이나 어셈블리 '파일을로드 할 수 없습니다 : /// C : \ Users {사용자 이름} \ AppData \ Local \ Temp \ qk3bjlf3.dll '또는 종속성 중 하나를 선택하십시오. 시스템이 지정된 파일을 찾을 수 없습니다.
문제는 파일이 실제로 어디에서나 참조되지 않는다는 것입니다. AppDomain.CurrentDomain.GetAssemblies() 및 하위 모듈에 의해 반환되지 않으며 디버거에서 계속을 클릭 할 때마다 이름이 변경됩니다.
동적으로 생성되는 어셈블리입니다. 그것은 단지 기억에있을 수 있습니다. –
'GenerateInMemory = true' –