简体   繁体   English

如何从项目内部获取某些内容到目录? (C#)

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

Here is my code:这是我的代码:

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 is in the same folder as Program.cs. ExampleProgram.exe 与 Program.cs 位于同一文件夹中。 Is there anything I can do?有什么我可以做的吗? I don't want ExampleProgram.exe to be seperate from the program, I want it to be inside the program, and then copied to that place.我不希望 ExampleProgram.exe 与程序分开,我希望它在程序内部,然后复制到那个地方。

How about to get the Path of your executing exe?如何获取执行 exe 的路径? Then you could spezify the copy process with the whole Path?那么你可以用整个路径指定复制过程吗?

eg.:例如。:

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

Haven't tested it, because I'm not at Work.没有测试它,因为我不在工作。

Kind Regards亲切的问候

It sounds like you want to store ExampleProgram.exe inside the program that your source code produces.听起来您想将 ExampleProgram.exe 存储在源代码生成的程序中。 If that is the case, you can store that ExampleProgram.exe as a resource within your program then read the resource and store it at the location of your choice.如果是这种情况,您可以将该 ExampleProgram.exe 作为资源存储在程序中,然后读取该资源并将其存储在您选择的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 C# 目录中获取文件 - How Do I get Files From C# Directory 如何从托管代码项目中调试本机代码项目? C++/C# - How do I debug a native code project from inside a managed code project? C++/C# 如何在 C# 中获取目录大小(目录中的文件)? - How do I get a directory size (files in the directory) in C#? 如何从编辑器分类器项目(c#)获取当前的解决方案目录? - How do you get the current solution directory from a Editor Classifier Project (c#)? 创建自定义MSBuild任务时如何从C#代码获取当前项目目录? - How do you get the current project directory from C# code when creating a custom MSBuild task? C#如何获取目录的名称而不是路径? - C# How do I get the name of a Directory instead of a path? 我如何使用 C# 从活动目录中获取 SID-History 值 - How do i get the SID-History value using c# from active directory 如何从使用C#的用户名获取存储在Active Directory中的真实姓名? - How do I get a real name stored in Active Directory from an username with C#? C# - 如何从 Active Directory 获取用户的“网页”属性? - C# - How do I Get a users "Web Page" property from Active Directory? 如何从C#项目文件中获取DLL或EXE名称? - How do I get a DLL or EXE name from a C# project file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM