简体   繁体   English

在Visual Studio下管理多个目标项目

[英]Manage multiple target projects under Visual Studio

I have written a Visual Studio C# project and I have the need to create two executable, one for a "lite version" and one for a "full version" of the same project. 我编写了一个Visual Studio C#项目,我需要创建两个可执行文件,一个用于“lite版本”,另一个用于同一项目的“完整版本”。

The "lite version" will be a stripped down version of the full one so I want to share everything (code, resources, etc.) and, if possible, use compiling directive to isolate code blocks. “精简版”将是完整版的精简版,所以我想分享所有内容(代码,资源等),如果可能的话,使用编译指令来隔离代码块。

Can you tell me a way to do this in a clean way? 你能告诉我一种以干净的方式做到这一点的方法吗?

You can create a new Conditional compilation symbol in your project (say FULLVERSION ). 您可以在项目中创建一个新的条件编译符号 (比如FULLVERSION )。 Create a new Solution configuration (say ReleaseFullversion) using the Configuration Manager , and in this configuration, define the FULLVERSION constant. 使用Configuration Manager创建新的解决方案配置 (例如ReleaseFullversion),并在此配置中定义FULLVERSION常量。


You can then wrap code block with 然后,您可以使用包装代码块

#if FULLVERSION
 ...
#end if

or use the Conditional atrribute 或使用条件属性

[Conditional("FULLVERSION")]
void MyMethod()
{...}

to create a stripped down version your application. 创建一个精简版本的应用程序。

Code within these #if -blocks and these Conditional attributes won't be compiled into your assembly if the FULLVERSION constant is not set (the Conditional attributes just removes the call to that code block, actually). 如果未设置FULLVERSION常量,则这些#if -block中的代码和这些Conditional属性将不会被编译到程序集中( Conditional属性实际上只删除了对该代码块的调用)。


Then you would either build a lite version of your solution, or a Fullversion, which includes the full code. 然后,您可以构建解决方案的精简版本,也可以构建包含完整代码的Fullversion。

You can use Visual Studio Post Build events, where from the batch call DEVENV.EXE to your project with some special parameter that makes it compile in a different way. 您可以使用Visual Studio Post Build事件,从批处理调用DEVENV.EXE到您的项目,其中包含一些特殊参数,使其以不同的方式进行编译。

DevEnv explanation DevEnv解释

Using Devenv at the command prompt to build projects 在命令提示符下使用Devenv来构建项目

To do this all within visual studio, you require something of a strange ritual that is a little non-obvious to anyone simply looking at your project, so it is important to figure out a training regimen to make sure everyone knows what is going on. 要在视觉工作室中完成这一切,你需要一些奇怪的仪式,对于任何只是看你的项目的人来说都是不明显的,所以找出一个训练方案以确保每个人都知道发生了什么是很重要的。

First, right-click on the solution you have and go to properties. 首先,右键单击您拥有的解决方案,然后转到属性。 Click on "Configuration Manager" and make a new configuration. 单击“Configuration Manager”并进行新配置。 Call it "Lite" or whatever pleases you. 称之为“精简版”或其他任何让你满意的东西。

You may then right-click each project in your solution to set the conditional compilation properties you need. 然后,您可以右键单击解决方案中的每个项目,以设置所需的条件编译属性。 You may then use Conditional Compilation Symbols to isolate what is 'full' and what is 'lite'. 然后,您可以使用条件编译符号来隔离“完整”和“精简”的内容。

After this has been fully configured, it will appear in the top of visual studio's UI - where you normally see Debug and Release, you will now see Lite or whatever you just configured. 在完全配置完成后,它将显示在visual studio的UI顶部 - 您通常会看到Debug和Release,现在您将看到Lite或您刚刚配置的任何内容。

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

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