简体   繁体   English

自动编译两个版本的C#程序

[英]Compile two versions of C# program automatically

I have to make the same program for two different companies (different logo, different name). 我必须为两个不同的公司制作相同的程序(不同的标识,不同的名称)。 I would like to have this done automatically when I do a release. 我希望在发布时自动完成此操作。

I am thinking to use a resource file or a satellite assembly, but I am not sure how to proceed. 我想使用资源文件或附属程序集,但我不知道如何继续。

Which way do you think is the best? 您认为哪种方式最好?

Thanks. 谢谢。

EDIT: 编辑:

  • The differences are only one image and one string. 差异只是一个图像和一个字符串。
  • I would like to have everything generated in one click. 我希望只需点击一下即可生成所有内容。
  • We might get more clients in the future. 我们将来可能会有更多的客户。
  • I must also add that I use SmartAssembly to merge all my dependencies into one exe file. 我还必须补充一点,我使用SmartAssembly将所有依赖项合并到一个exe文件中。

You could create a class library that contains 99% of the code, and then have two projects which each reference the common library with the 1% that differs for each company. 您可以创建一个包含99%代码的类库,然后有两个项目,每个项目引用公共库,每个公司的1%不同。 Then a build of the whole solution will generate an executable for each company. 然后,整个解决方案的构建将为每个公司生成可执行文件。 Use this if the differences between what each company wants is just enough that you need to have [slightly] different code. 如果每个公司想要的差异足以让您需要[稍微]不同的代码,请使用此选项。

Alternatively, you could make the sections that vary dependent on data, not code. 或者,您可以根据数据而不是代码来设置不同的部分。 In this case, it might mean getting the logo from a file, rather than embedding it in the executable, and having a configuration xml file with the company name. 在这种情况下,它可能意味着从文件中获取徽标,而不是将其嵌入可执行文件中,并具有带有公司名称的配置xml文件。 This would allow you to have just a single executable for both companies. 这将允许您只为两家公司提供一个可执行文件。

Resource string in separate assembly would be the easiest distribution. 单独汇编中的资源字符串将是最简单的分发。

But honestly, I'd have it be a customization feature. 但老实说,我认为它是一个自定义功能。 Last thing you want is to maintain everyone's logo changes due to: legal reasons, copywrite cases, whimsical artistic license, etc. 您想要的最后一件事是维护每个人的徽标更改,原因包括:法律原因,copywrite案例,异想天开的艺术许可等。

Which is short for.... have them provide a formatted image, and have them assign the company name during installation and store that off in the registry or in a meta file of some type (XML, manifest, etc.) 对于....让他们提供一个格式的图像,并让他们在安装过程中指定的公司名称和存储关闭注册表或在某些类型(XML,清单等)的元文件这是短期

The best I can think of it a batch script. 我能想到的最好是批处理脚本。

Get your project to reference files (images (logo), text (company name), etc). 让您的项目引用文件(图像(徽标),文本(公司名称)等)。 ie C:\\MyProject\\Resources. 即C:\\ MyProject \\ Resources。 So that when the project builds it complies them into the application/installer etc. 因此,当项目构建时,它将符合应用程序/安装程序等。

This way, you can write a script (.bat file) which copies in the resources needed per company. 这样,您就可以编写一个脚本(.bat文件),该脚本可以复制每个公司所需的资源。

Step 1 - Delete all files in the Resources folder 步骤1 - 删除Resources文件夹中的所有文件

Step 2 - Use MSBuild.exe to build you project 第2步 - 使用MSBuild.exe构建项目

Step 3 - Copy the files needed from the bin/release folder to a directory (ie C:\\Release\\CompanyA) 步骤3 - 将bin / release文件夹中所需的文件复制到目录(即C:\\ Release \\ CompanyA)

Step 4 - Change the variables in the script to load the details for the next company. 第4步 - 更改脚本中的变量以加载下一个公司的详细信息。 And repeat from step 1, so it copies over the needed resource files and rebuilds. 并从步骤1重复,因此它复制所需的资源文件并重建。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM