简体   繁体   English

Visual Studio项目构建为可执行文件和DLL

[英]Visual Studio project build as an executable AND a DLL

In Visual Studio 2008 project properties, Application tab, I can set the Output type to Windows Application, Console Application, or Class Library. 在Visual Studio 2008项目属性的“应用程序”选项卡中,我可以将输出类型设置为Windows应用程序,控制台应用程序或类库。 I have a project that I want to build as a stand-alone tool (console app) and be available to a couple other tools I'm working on as a class library. 我有一个项目,我想构建一个独立的工具(控制台应用程序) 并可用于我正在作为类库工作的其他几个工具。

The VS GUI only lets me choose one or the other, and building the proj twice all the time is inconvenient. VS GUI只允许我选择其中一个,并且一直两次构建项目是不方便的。

How can I set it up to build both output types in a single build job? 如何设置它以在单个构建作业中构建两种输出类型? Do I write some custom MSBuild .targets file or what? 我是否写了一些自定义的MSBuild .targets文件或者什么?

If I'm not mistaken, you can use the EXE as a class library. 如果我没弄错的话,你可以将EXE用作类库。
Just add a reference to it, in the other projects. 只需在其他项目中添加对它的引用即可。 A .NET EXE is just an assembly. .NET EXE只是一个程序集。

您可以默认构建dll,并创建另一个依赖目标,它只是一个使用dll的包装器控制台应用程序。

Create two separate projects, one for your Console app and one for the Class library. 创建两个单独的项目,一个用于Console应用程序,另一个用于Class库。 Set the appropriate Output type for each. 为每个设置适当的输出类型。

Don't forget to add a reference to your Class library to your Console app project though. 不要忘记将类库的引用添加到Console应用程序项目中。

You cannot compile to both an exe and a dll. 你无法编译exe和dll。 Whether an assembly is treated as an exe or a dll is determined by a single bit flag in the portable executable header of the file (see http://msdn.microsoft.com/en-us/magazine/cc301805.aspx for more info). 是否将程序集视为exe或dll由文件的可移植可执行文件头中的单个位标志确定(有关详细信息,请参阅http://msdn.microsoft.com/en-us/magazine/cc301805.aspx) )。 This flag cannot have both values. 此标志不能同时具有这两个值。

What you can do to satisfy your need is to add a reference to your exe . 您可以做些什么来满足您的需求是添加对您的exe的引用 You cannot do this in some versions of Visual Studio (2005 and below) as the UI will not let you, but you can hand edit the project file to add the reference. 您无法在某些版本的Visual Studio(2005及更低版本)中执行此操作,因为UI不会让您,但您可以手动编辑项目文件以添加引用。 Later versions of Visual Studio do allow you to add references to exe files using the UI. 更高版本的Visual Studio允许您使用UI添加对exe文件的引用。

I think the simplest solution is to build as a EXE and then have a post build action which copies the EXE into a DLL. 我认为最简单的解决方案是构建为EXE,然后进行后构建操作,将EXE复制到DLL中。 There is no real difference between the two in .Net. 在.Net中,两者之间没有真正的区别。

暂无
暂无

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

相关问题 如何在 Visual Studio 2010 中构建不依赖于 .NET 4 SDK DLL/库文件的可执行文件? - How do I build an executable file in visual studio 2010 that doesn't rely on the .NET 4 SDK DLL/Library files? 如何在 Visual Studio 或其他构建工具的一个 C# 项目中生成 dll 和 exe 的混合体? - how to produce a mix of dll and exe in one C# project in visual studio or other build tools? 在Visual Studio中向.NET项目添加非引用dll时的正确构建操作 - Proper build action when adding a non-reference dll to a .NET project in Visual Studio Visual Studio解决方案项目参考或DLL参考 - Visual Studio Solution Project Reference or Dll Reference Nuget Pkg Dll 在.Net 标准 DLL 项目中的构建文件夹中丢失。 dll不是本地复制? 在 Visual Studio 2019 中修复? - Nuget Pkg Dlls Missing from Build Folder in .Net Standard DLL Project. dlls are Not Copy Local? Fix in Visual Studio 2019? 对于我在 Visual Studio 2013 中的类库项目; 使用后期构建事件如何将创建的 dll 复制到另一个路径? - For my class Library project in visual Studio 2013 ; Using post build event how do I copy the created dll to another path? Visual Studio 2017不会生成项目 - Visual Studio 2017 wont build project Visual Studio 2010不会生成新项目 - Visual Studio 2010 does not build new project 查找在其上构建exe / dll的Visual Studio版本(C#) - Find visual studio release on which an exe/dll was build (C#) 从属 DLL 未被复制到 Visual Studio 中的构建 output 文件夹 - Dependent DLL is not getting copied to the build output folder in Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM