My solution is primarily C#, but I have one C++ project that creates a DLL which my C# code calls. Here's the layout:
我的解决方案主要是C#,但我有一个C ++项目,它创建了一个我的C#代码调用的DLL。这是布局:
[Edited: there are two levels of indirection, which causes the problem]
[编辑:有两个级别的间接,导致问题]
We'll call the solution MySolution. It has four projects:
我们称之为解决方案MySolution。它有四个项目:
MySolution MyCppDll (creates an unmanaged DLL) MyCSharpWrapper (Managed wrapper for the unmanaged DLL) MyCSharpLibrary (Contains classes that access the wrapper) MyCSharpProgram (Creates classes from MyCSharpLibrary)
I have the dependencies set up correctly so that MyCppDll is compiled first, then the wrapper, the library, and the program. However, when building within the IDE, the output of MyCppDll isn't copied to the output directory of MyCSharpLibrary.
我正确设置了依赖项,以便首先编译MyCppDll,然后编译包装器,库和程序。但是,在IDE中构建时,MyCppDll的输出不会复制到MyCSharpLibrary的输出目录中。
I can get around that problem by creating a post-build step for MyCSharpLibrary, making it copy MyCppDll.dll to the MyCSharpLibrary\bin\Debug (or \Release) directory.
我可以通过为MyCSharpLibrary创建一个构建后步骤来解决该问题,使其将MyCppDll.dll复制到MyCSharpLibrary \ bin \ Debug(或\ Release)目录。
But then when MyCSharpProgram is compiled, it gets the files associated with the wrapper and the library, but it doesn't get the DLL. Again, I could create a post-build step to do it, but that's less than ideal, for a couple of reasons.
但是当编译MyCSharpProgram时,它会获取与包装器和库相关联的文件,但它不会获得DLL。同样,我可以创建一个后期构建步骤,但由于几个原因,这不太理想。
The real solution has several dozen projects, many of which reference MyCSharpLibrary. Creating a post-build step for each one is, as you can imagine, tiresome and error-prone. And every time I add a new project that references that assembly, I'll have to create another post-build step.
真正的解决方案有几十个项目,其中许多参考MyCSharpLibrary。正如您可以想象的那样,为每个人创建一个构建后的步骤,令人厌烦且容易出错。每次我添加一个引用该程序集的新项目时,我都必须创建另一个构建后的步骤。
And it shouldn't be necessary. When I build that solution from the command line, the DLL is copied from the MyCSharpLibrary directory as expected. That is, building from the IDE, the directory MyCSharpProgram\bin\Debug contains MyCSharpProgram.exe, MyCSharpLibrary.dll, MyCSharpWrapper.dll (plus the associated .pdb files). But if I build from the command line (using MSBuild), the directory contains all that AND MyCppDll.dll.
它不应该是必要的。当我从命令行构建该解决方案时,DLL将按预期从MyCSharpLibrary目录复制。也就是说,从IDE构建,目录MyCSharpProgram \ bin \ Debug包含MyCSharpProgram.exe,MyCSharpLibrary.dll,MyCSharpWrapper.dll(以及相关的.pdb文件)。但是如果我从命令行构建(使用MSBuild),该目录包含所有AND MyCppDll.dll。
Has anybody else run into this problem? I'm using Visual Studio 2008 and haven't yet upgraded to SP1.
还有其他人遇到过这个问题吗?我正在使用Visual Studio 2008,尚未升级到SP1。
[Edit - The problem appears to be that the files aren't copied unless there is a direct reference from the Program project to the Wrapper project. That is, if I add a reference to MyCSharpWrapper in the MyCSharpProgram project, then the DLL is copied. Again, this only happens in the IDE. It works fine without that reference when building from the command line.]
[编辑 - 问题似乎是除非从程序项目直接引用到Wrapper项目,否则不会复制文件。也就是说,如果我在MyCSharpProgram项目中添加对MyCSharpWrapper的引用,则会复制DLL。同样,这只发生在IDE中。从命令行构建时,它在没有该引用的情况下工作正常。]
1 个解决方案
#1
We had issues with visual studio and mixed C++ and C# projects when using Build. Then we switched to only use Rebuild and it worked. You probably Rebuild from the command line and Build in the IDE.
使用Build时,我们遇到了visual studio和混合C ++和C#项目的问题。然后我们切换到只使用Rebuild并且它有效。您可能从命令行重建并在IDE中构建。
By the way, couldn't it be that this reference needs to be there, because the project depends on it somehow?
顺便说一下,这个参考不一定需要在那里,因为项目在某种程度上取决于它吗?
#1
We had issues with visual studio and mixed C++ and C# projects when using Build. Then we switched to only use Rebuild and it worked. You probably Rebuild from the command line and Build in the IDE.
使用Build时,我们遇到了visual studio和混合C ++和C#项目的问题。然后我们切换到只使用Rebuild并且它有效。您可能从命令行重建并在IDE中构建。
By the way, couldn't it be that this reference needs to be there, because the project depends on it somehow?
顺便说一下,这个参考不一定需要在那里,因为项目在某种程度上取决于它吗?