简体   繁体   English

如何在C#中将程序编译为不同的项目

[英]How to compile a program into different projects in C#

Let us say that: I have a project, this project uses a references (office2016.dll). 让我们说:我有一个项目,该项目使用引用(office2016.dll)。 in my project I have ac# classes that access these references and works fine. 在我的项目中,我有ac#类,可以访问这些引用并可以正常工作。

Now I want to compile the same code but by using different references, this time (office2012.dll). 现在,我想这次使用(office2012.dll)编译相同的代码,但使用不同的引用。 note that (office2016.dll & office2012.dll) are sharing the same methods and types that I used in my c# code. 请注意,(office2016.dll和office2012.dll)共享与我的C#代码中使用的相同的方法和类型。 but I want to publish different (EXE) for each product. 但我想为每种产品发布不同的(EXE)。 one for office 2016, and another for office 2012. 一个用于Office 2016,另一个用于Office 2012。

Is it possible to compile the same c# code on different references (dll)? 是否可以在不同的引用(dll)上编译相同的c#代码?

One solution is to copy my c# code in a new project and then add the other (office2012.dll) and then recompile again, it works and fine but I would n't like to do that manually because I work every day and it requires many efforts and concentrations and of course extra time, because really I don't believe on copy/paste code, this is actually a tedious work! 一种解决方案是将我的C#代码复制到一个新项目中,然后添加另一个代码(office2012.dll),然后再次重新编译,它可以正常工作,但是我不希望手动执行此操作,因为我每天都在工作,并且需要许多工作和精力,当然还有额外的时间,因为我真的不相信复制/粘贴代码,这实际上是一件乏味的工作!

You can create copies of the project file (the .csproj ) in the same folder , then include the copied project(s) in your solution. 您可以在同一文件夹中创建项目文件( .csproj )的副本,然后将复制的项目包括在解决方案中。 You can then pick the correct references for each project. 然后,您可以为每个项目选择正确的引用。 Make sure to go to the project properties and choose a custom assembly name and/or output folder for each project (ie. myoffice2012app.exe and/or bin/Release2012 ). 确保转到项目属性,并为每个项目选择自定义程序集名称和/或输出文件夹(即myoffice2012app.exe和/或bin/Release2012 )。

Any code file you add afterwards will have to be included in each copy, but this is simplified by selecting "show all files": 之后添加的任何代码文件都必须包含在每个副本中,但是通过选择“显示所有文件”可以简化此操作:

在此处输入图片说明

right-clicking the new files and selecting "Include In Project" - but besides having to add each new code file to each project separately, you can build the solution as often as you want without further steps needed. 右键单击新文件,然后选择“包含在项目中”-但是除了必须将每个新的代码文件分别添加到每个项目之外,您还可以根据需要多次构建解决方案,而无需采取进一步的步骤。

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

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