5

重複の可能性:
c# .exe に .net dll を埋め込む

.dll (具体的には Ionic.Zip.dll) をアプリケーションに埋め込もうとしましたが、CodeDom を使用して新しい .exe をコンパイルし、Ionic.Zip.dll を必要とします。.dll を追加せずにプログラムを配布できるようにしたいと考えています。作業ディレクトリに DLL がある場合、プログラムとコンパイルされたプログラムは正常に実行されます。コンパイルされたプログラムには .dll が必要であり、ユーザーに ILMerge の取得を強制することはできないため、ILMerge を使用していません。ただし、.dll がない場合、このエラーが発生します。

元のプログラムは、このエラーでコードをコンパイルしません

error CS0006: Metadeta file 'Ionic.Zip.dll" could not be found.

コンパイル済みプログラム (元のプログラムの作業ディレクトリにdllを置いてコンパイル)

Description:
Stopped working

Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01:   scrub.exe
Problem Signature 02:   0.0.0.0
Problem Signature 03:   50b0f364
Problem Signature 04:   Scrub
Problem Signature 05:   0.0.0.0
Problem Signature 06:   50b0f364
Problem Signature 07:   1
Problem Signature 08:   38
Problem Signature 09:   System.IO.FileNotFoundException
OS Version: 6.1.7601.2.1.0.256.48
Locale ID:  1033

デバッグ エラー

Could not load file or assembly 'Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c' or one of its dependencies. The system cannot find the file specified.

CodeDom コンパイラ内で、次のコードを使用しました。

Params.ReferencedAssemblies.Add("Ionic.Zip.dll");

これを修正するために、私はこれを試し、できる限りそれに従いました。http://adamthetech.com/2011/06/embed-dll-files-within-an-exe-c-sharp-winforms/

元のアプリケーション内の私のコードは次のとおりです。

        public MainWindow()
    {
        AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
        {
            string resourceName = new AssemblyName(args.Name).Name + ".dll";
            string resource = Array.Find(this.GetType().Assembly.GetManifestResourceNames(), element => element.EndsWith(resourceName));

            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
            {
                Byte[] assemblyData = new Byte[stream.Length];
                stream.Read(assemblyData, 0, assemblyData.Length);
                return Assembly.Load(assemblyData);
            }
        };

        InitializeComponent();

        inniZip();
     }

    private void inniZip()
    {
        Ionic.Zip.ZipOption test = new Ionic.Zip.ZipOption();
    }

コンパイル済みプログラム ソースにも同様のコードを入れました。私はしばらくこのエラーに悩まされていましたが、それを理解できないようです。

前もって感謝します、

4

0 に答える 0