簡體   English   中英

如何從項目內部獲取某些內容到目錄? (C#)

[英]How do I get something from inside a project to a directory? (C#)

這是我的代碼:

using System;

namespace msoApplier
{
    class Program
    {
        static void Main()
        {
            string targetPath = @"C:\Program Files (x86)\MyProgram";          

            System.IO.Directory.CreateDirectory(targetPath);
            System.IO.File.Copy("ExampleProgram.exe", targetPath);
            Console.ReadKey();
        }
    }
}

ExampleProgram.exe 與 Program.cs 位於同一文件夾中。 有什么我可以做的嗎? 我不希望 ExampleProgram.exe 與程序分開,我希望它在程序內部,然后復制到那個地方。

如何獲取執行 exe 的路徑? 那么你可以用整個路徑指定復制過程嗎?

例如。:

string SourceDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
string SourceFile = SourceDir + "\ExampleProgram.exe";
System.IO.File.Copy(SourceFile , targetPath);

沒有測試它,因為我不在工作。

親切的問候

聽起來您想將 ExampleProgram.exe 存儲在源代碼生成的程序中。 如果是這種情況,您可以將該 ExampleProgram.exe 作為資源存儲在程序中,然后讀取該資源並將其存儲在您選擇的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM