Visual Studio中没有抄袭间接引用的项目内容文件文件、项目、内容、Visual

2023-09-02 12:02:50 作者:-风尘乱迷魂,

我有以下项目结构:

Library1 <--[project reference]-- Library2 <--[ref]-- Executable
--------                          --------            ----------
ContentFile                      .cs files           .cs files
.cs files

所有的项目都引用= CopyLocal真。

All project references have CopyLocal = true.

当我构建项目,在 ContentFile 的被复制到 Library2 输出目录,而不是可执行的输出目录,这意味着可执行文件丢失 ContentFile 当应用程序运行。

When I build the project, the ContentFile gets copied to Library2's output directory, but not to Executable's output directory, meaning that the executable is missing ContentFile when the application runs.

为什么内容文件复制到 Library2 的输出目录,而不是可执行的?有没有一种方法也将其复制到后者的(我想这样做,没有生成事件,因为我敢肯定,人们会忘了)?

Why is the content file being copied to Library2's output directory, but not Executable's? Is there a way to also copy it to the latter (I'd like to do that without build events because I'm sure people will forget that)?

我要寻找一个合理的维护的解决方案;一个需要最小的努力增加新的项目时的或的新间接引用的内容的文件,因此,这是不太可能的能够简单地忘记这样做。

I am looking for a reasonable and maintainable solution; one that requires minimal effort when adding new projects or new indirectly referenced content files, so that it is as unlikely as possible to simply forget doing it.

使用生成后事件(如 XCOPY ../Library/bin/Debug/SomeDll.dll斌/调试);和手动设置项目的输出目录 $(SolutionDir)/箱/...,双双迅速成为一个巨大的混乱。添加内容文件的链接中的主体工程太繁琐,以及。这将是罚款,如果C#有相同的默认设置输出​​文件的Visual C ++那样(即 $ SolutionDir / $平台/ $配置),但它不吨。

Using Post-Build events (like xcopy ../Library/bin/Debug/SomeDll.dll bin/Debug); and manually setting the output directory of projects to $(SolutionDir)/bin/... instead of the default (per-project basis), have both quickly become a huge mess. Adding the content files as links in the "main project" was too tedious as well. It would be fine if C# had the same default setting for the output file as Visual C++ does (that is, $SolutionDir/$Platform/$Configuration), but it doesn't.

我也认为不使用标准的MSBuild程序都写一个自定义生成目标(如使用gcc爱特梅尔Studio中),但我并没有走远的。此外,我想Visual Studio的标准构建和调试命令来工作,因为他们通常做的。

I've also considered not using the standard MSBuild procedure at all and write a custom build target (like using gcc in Atmel Studio), but I didn't get far at all. Furthermore, I want Visual Studio's standard "Build" and "Debug" commands to work as they usually do.

下面是详细的我在做什么。

Here is more detail on what I am doing.

我有一个可执行项目的解决方案。此外,还有一堆,你可以调用插件取值项目。 可执行引用那些插件虏通过托管项目的参考。

I have a solution with an Executable project. Furthermore, there is a bunch of projects that you could call Plugins. Executable references all those Plugins via a managed project reference.

由于插件项目量身定做的可执行文件,但可能有重复使用的组件,其主要功能是经常在外部项目的实施,使插件项目仅仅包装(不总是虽然)。

Since the plugin projects are tailored to the executable, but may have reusable components, the main functionality is often implemented in an External project, leaving the Plugin project a mere wrapper (not always though).

外部项目有时会使用第三方提供的本机DLL。这些DLL,然后添加到外部的项目作为内容文件,并有复制到输出目录设置为复制总是。因此,结构类似于上面的图:

Said External projects sometimes use native DLLs provided by third parties. Those DLLs are then added to the External project as a content file and have Copy to output dir set to Copy always. So the structure looks like the diagram above:

External <---------------[is not aware of]--------------------+
--------                                                      |
.cs files <--[reference]-- PluginWrapper <--[reference]-- Executable
"Native DLL"               -------------                  ----------
                           .cs files                      .cs files

奇怪的是,该本机DLL被复制到外部的输出目录(明显),以及 PluginWrapper 的而不是的可执行的。

The weird thing is, that the "Native DLL" gets copied to External's output directory (obviously), as well as PluginWrapper's, but not Executable's.

开发人员的工作流程将被写在外部这可以作为一个完全独立的实体(它们的在的被重复使用很频繁),包它有一个 PluginWrapper ,然后只添加项目引用 PluginWrapper 可执行。我觉得很奇怪,这显然是这样一个罕见的事情。

The developer's workflow would then be to write an External that works as a completely isolated entity (they are being reused very often), wrap it with a PluginWrapper, and then only add a project reference to the PluginWrapper to Executable. I find it odd that this is apparently such an uncommon thing to do.

我想,也许编辑可执行的MSBuild的目标XML(也包括间接引用的内容文件)可能已解决了这个问题。

I thought that maybe editing Executable's MSBuild target XML (to also include indirectly referenced content files) could have solved the problem.

我可能要考虑添加DLL文件的项目,嵌入的资源的建议,但嵌入机DLL一样,似乎怪我。最后,改变了开发人员的工作流程通过剥离了[不知道]从上面的图并添加项目引用外部,因为布伦达贝尔建议,不妨是最明智的解决方案,即使不理想。

I might want to look into adding the DLLs to the projects as embedded resources as suggested, but embedding native DLLs like that seems weird to me. In the end, changing the developer's workflow by stripping the '[is not aware of]' from the above diagram and adding a project reference to External, as Brenda Bell suggested, might be the most sensible solution, even if not ideal.

更新2 的

请注意,嵌入式种源的想法可能并不适用于所有情况。如果有必要放置在可执行文件的目录的依赖(未CWD或任何东西),那么这可能不是因为在安装文件夹(解包从嵌入式资源的文件)缺少管理员权限的工作。听起来不可思议,但是这是一个严重的问题,我们都用上了。

Note that the embedded resouce idea may not work in all cases. If it is necessary to place a dependency in the executable's directory (not cwd or anything), then this may not work because of missing administrator privileges in the installation folder (to unpack the file from the embedded resource). Sounds weird, but this was a serious issue with one of the 3rd party libraries we were using.

推荐答案

添加LIBRARY1参考可执行项目。

Add Library1 reference to the Executable project.

 
精彩推荐
图片推荐