简体   繁体   English

哪种构建操作(C#Microsoft Visual Studio)适合启动Windows窗体内具有零个或多个依赖项的.exe软件?

[英]Which Build Action (C# Microsoft Visual Studio) is suitable for launching an .exe software which has zero or more dependents within a Windows Form?

Consider these two software: MyGame.exe and SocketTest.exe . 考虑以下两个软件: MyGame.exeSocketTest.exe

MyGame.exe doesn't depend on any files to run but SocketTest.exe is an actual software. MyGame.exe不依赖于任何文件来运行,但是SocketTest.exe是实际的软件。 It can only run if one or more of four other files are in the same folder as itself. 仅当其他四个文件中的一个或多个与它自己位于同一文件夹中时,它才能运行。 These files are: metouia.jar , SocketTest.bat , SocketTest.jar , SocketTest.sh 这些文件是: metouia.jarSocketTest.batSocketTest.jarSocketTest.sh

I want to create a software using Windows Form in Microsoft Visual Studio using C#. 我想使用C#在Microsoft Visual Studio中使用Windows窗体创建软件。 It will have two buttons: "Launch MyGame" and "Launch SocketTest." 它将具有两个按钮:“启动MyGame”和“启动SocketTest”。

I go to the Solution Explorer tab and right-click my .csproj file to click Add Existing Item... so I can add MyGame.exe , SocketTest.exe and the other four files into the Solution Explorer. 我转到“ 解决方案资源管理器”选项卡,然后右键单击我的.csproj文件以单击“ 添加现有项...”,以便将MyGame.exeSocketTest.exe和其他四个文件添加到解决方案资源管理器中。

For the File Properties of the 6 files, under " Copy to Output Directory " I choose "Copy Always." 对于6个文件的文件属性,在“ 复制到输出目录 ”下,选择“始终复制”。

For Build Action , I'm not sure. 对于Build Action ,我不确定。 I use "None". 我使用“无”。 My buttons can still launch the two .exe files. 我的按钮仍然可以启动两个.exe文件。

However, I'm not sure which settings to use if I want other computers to be able to launch those .exe files with my software, especially for the .exe file that depends on other files. 但是,如果我希望其他计算机能够使用我的软件启动那些.exe文件,特别是对于依赖于其他文件的.exe文件,我不确定要使用哪些设置。 I've read the Build Action descriptions (online too) but still can't decide on the proper one for my situation. 我已经阅读了Build Action的说明(也在线),但是仍然无法确定适合我的情况的方法。

The way your're doing it is fine. 您的操作方式很好。 A few notes: 一些注意事项:

  • Instead of "Copy Always", you can use "Copy only if newer" 您可以使用“仅在较新版本时复制”,而不是“始终复制”
  • For "Add Existing Item...", instead of adding the items directly, you can pull down the "Add" button and select "Add link" - this will keep the files in sync with the source items, in case they are updated 对于“添加现有项目...”,您可以下拉“添加”按钮并选择“添加链接”,而不是直接添加项目-如果文件已更新,这将使文件与源项目保持同步
  • Build action "none" is correct. 生成操作“无”是正确的。 You are not building these items, just copying them to your output folder. 您不是在构建这些项目,只是将它们复制到您的输出文件夹中。

Whatever you do with your project -- publish, deploy, etc -- the added items will stay with your project output. 无论您对项目做什么(发布,部署等),添加的项目都将保留在项目输出中。

Good luck! 祝好运!

Rather than adding artefacts into your launcher which just produce noise as far as the . 与其在发射器上加些人造的东西,否则只会产生直至发射的噪音 csproj is concerned, consider using build events . 对于csproj ,请考虑使用build事件

Right click your launcher's project, choose Properties then Build Events . 右键单击启动器的项目,选择属性,然后选择构建事件 In the Post-build event command line enter appropriate copy commands to copy your binaries and artefacts from your other project folders to your launcher's OutDir folder. “构建后事件”命令行中,输入适当的复制命令,以将您的二进制文件和OutDir从其他项目文件夹复制到启动器的OutDir文件夹中。

Anything more and you should probably look into making an installer. 还有更多,您可能应该考虑制作安装程序。

暂无
暂无

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

相关问题 查找在其上构建exe / dll的Visual Studio版本(C#) - Find visual studio release on which an exe/dll was build (C#) 如何在Microsoft Visual C#2010 Express中更改Windows窗体应用程序的启动图标 - How to change launching icon of windows form application in microsoft visual c# 2010 express 如何防止在 Windows 窗体应用程序构建中创建 .exe.config(Visual Studio 社区 2019 - C#) - How prevent to create a .exe.config in a Windows Forms Application build (Visual Studio Community 2019 - C#) 初始化 C# Visual Studio Windows 窗体应用程序后,如何更改窗体的视觉效果? - How do I change the visual of a form after it has Initialized C# Visual Studio Windows Form App? 在安装了Visual Studio 2010的计算机上运行的C#.net exe,但是仅安装.net 4.0客户端配置文件时,它没有响应 - C# .net exe running on machine which has visual studio 2010 installed, however it is not responding where only .net 4.0 client profile is installed 如何使用 Microsoft Visual Studio 使用 C# windows 窗体将文件中的图像加载到图片框 - How to load image from file into picturebox using C# windows form using Microsoft Visual Studio 如何使用 C# 在 Visual Studio 上构建我的项目的 exe - how to build exe of my project on visual studio using c# Microsoft Visual Studio C#2010 Express:可以调试但不能构建 - Microsoft Visual Studio C# 2010 Express: Can debug but not build Visual Studio Windows 服务 c# exe 文件丢失 - Visual Studio Windows Service c# exe file missing 我用C#开发了一个应用程序,是否可以在没有SQL Server和Visual Studio的另一台PC上运行该应用程序 - I developed an application in C#, is it possible to run this application on another PC which has no SQL Server and Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM