在 Visual Studio 中编译时如何将 DLL 保存在不同的文件夹中?
假设我有一个窗口窗体 / 控制台应用程序 C# 项目,其中包含一些外部引用以及对其他类库的引用项目也在同一解决方案中。
当我构建Window Form项目时,我希望将引用的库存储在不同的位置(例如:bin\Release\Libraries), 并且与 .exe 不在同一文件夹中。
可以吗?
Let's suppose I have a Window Forms / Console Application C# project with some external references and references to other class library projects in the same solution too.
When I build the Window Form project, I want the referenced libraries be stored in a different location (eg: bin\Release\Libraries), and not in the same folder as the .exe.
Is it possible to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您的问题有两个部分:
如何配置解决方案以将程序集/EXE 构建到您选择的文件夹中 - 这是通过 VS 中项目的属性进行配置的(项目属性 -> 构建 -> 输出路径)。还检查每个引用上的“复制本地”属性的值。
如何从非默认位置(即从 ...\Libraries 文件夹)加载程序集文件 - 您需要更改 app.config 文件以将此非默认路径添加到程序集搜索位置。
链接到 Microsoft 站点不再有效,因此来自回程机器的摘要: 如何在运行时加载位于应用程序 bin 文件夹之外的文件夹中的程序集:
There are 2 parts of your question:
How to configure solutions to build assemblies/EXE into folders of your choice - this is configured through properties of the project in VS (project properties -> build -> output path). Also value of check "copy local" property on each reference.
How to load assemblies files from non-default locations (i.e. from your ...\Libraries folder) - you need to make changes to your app.config file to add this non-default paths to assembly search location..
Link to Microsoft site no longer works, so summary from wayback machine: How to load an assembly at runtime that is located in a folder that is not the bin folder of the application:
前面已经给出了正确答案。我只想提一下,有一个名为 PrettyBin 的 nuget 包。
将其安装到您的启动项目中。 DLL 和 XML 将转到 lib 文件夹,如果您不想自定义,您将获得一个说明其工作原理的工作示例。
Correct answers were given earlier. I'll just mention that there is a nuget package for this called PrettyBin.
Install it on your startup project. DLLs and XMLs will go to a lib folder and you'll have a working example of how it's done, if you won't to customize.
在项目属性中设置引用路径。
您还可以通过在项目对象中指定输出路径来指定编译后的 exe 的去向。
Set Reference path in project peoperties.
You can also specify where your compiled exe goes by specifying Output path in project peoperties.
您可以在此处找到组织项目参考的最佳实践:http://codebetter.com/patricksmacchia/2009/01/11/lessons-learned-from-the-nunit-code-base/
查看“VisualStudio 项目参考 + 复制本地 true”一章选择是邪恶的!”
You'll find best practices for organizing project references here: http://codebetter.com/patricksmacchia/2009/01/11/lessons-learned-from-the-nunit-code-base/
Look under chapter "The VisualStudio Project Reference + Copy Local true option is evil!"
是的,这是可能的,您可以在 msbuild 脚本中执行此操作。虽然我无法给您确切的答案,但请查看这里的问题 使用 msbuild 复制所有文件和文件夹
Yes it is possible, you'd do it in your msbuild script. While I can't give you an exact answer, look here at this question on SO Copy all files and folders using msbuild