我编写了一个Visual Studio C#项目,我需要创建两个可执行文件,一个用于“lite版本”,另一个用于同一项目的“完整版本”。
“精简版”将是完整版的精简版,因此我想分享所有内容(代码,资源等),如果可能的话,使用编译指令来隔离代码块。
你能告诉我一个以干净的方式做到这一点的方法吗?
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.
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?
最满意答案
您可以在项目中创建一个新的条件编译符号 (比如FULLVERSION )。 使用Configuration Manager创建新的解决方案配置 (例如ReleaseFullversion),并在此配置中定义FULLVERSION常量。
然后,您可以使用包装代码块
#if FULLVERSION ... #end if或使用有条件的atrribute
[Conditional("FULLVERSION")] void MyMethod() {...}为您的应用程序创建一个精简版本。
如果未设置FULLVERSION常量,则这些#if -block中的代码和这些Conditional属性将不会编译到程序集中( Conditional属性实际上只删除了对该代码块的调用)。
然后,您可以构建解决方案的精简版本,也可以构建包含完整代码的Fullversion。
You can create a new Conditional compilation symbol in your project (say FULLVERSION). Create a new Solution configuration (say ReleaseFullversion) using the Configuration Manager, and in this configuration, define the FULLVERSION constant.
You can then wrap code block with
#if FULLVERSION ... #end ifor 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).
Then you would either build a lite version of your solution, or a Fullversion, which includes the full code.
在Visual Studio下管理多个目标项目(Manage multiple target projects under Visual Studio)我编写了一个Visual Studio C#项目,我需要创建两个可执行文件,一个用于“lite版本”,另一个用于同一项目的“完整版本”。
“精简版”将是完整版的精简版,因此我想分享所有内容(代码,资源等),如果可能的话,使用编译指令来隔离代码块。
你能告诉我一个以干净的方式做到这一点的方法吗?
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.
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?
最满意答案
您可以在项目中创建一个新的条件编译符号 (比如FULLVERSION )。 使用Configuration Manager创建新的解决方案配置 (例如ReleaseFullversion),并在此配置中定义FULLVERSION常量。
然后,您可以使用包装代码块
#if FULLVERSION ... #end if或使用有条件的atrribute
[Conditional("FULLVERSION")] void MyMethod() {...}为您的应用程序创建一个精简版本。
如果未设置FULLVERSION常量,则这些#if -block中的代码和这些Conditional属性将不会编译到程序集中( Conditional属性实际上只删除了对该代码块的调用)。
然后,您可以构建解决方案的精简版本,也可以构建包含完整代码的Fullversion。
You can create a new Conditional compilation symbol in your project (say FULLVERSION). Create a new Solution configuration (say ReleaseFullversion) using the Configuration Manager, and in this configuration, define the FULLVERSION constant.
You can then wrap code block with
#if FULLVERSION ... #end ifor 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).
Then you would either build a lite version of your solution, or a Fullversion, which includes the full code.
发布评论