Visual Studio(2008)混合模式项目依赖项。 C-sharp项目依赖于C ++ DLL,但C ++ DLL没有重新构建

时间:2022-06-28 05:27:02

I have a Visual Studio 2008 solution with two projects in it. A C++ DLL and a Csharp application.

我有一个Visual Studio 2008解决方案,其中包含两个项目。 C ++ DLL和Csharp应用程序。

The Csharp application uses [DllImport] to access the functions in the DLL, and has a dependency set on the DLL.

Csharp应用程序使用[DllImport]访问DLL中的函数,并在DLL上设置依赖项。

For some reason, setting the dependency isn't sufficient to cause VS to copy the DLL to the build path of the app. So the app project has a post-build event which causes the DLL to get copied. (If anyone knows of a cleaner way of doing this, please let me know!)

出于某种原因,设置依赖关系不足以导致VS将DLL复制到应用程序的构建路径。所以app项目有一个post-build事件,导致DLL被复制。 (如果有人知道更清洁的方式,请告诉我!)

The problem I have is that when I make a change to the DLL code, then attempt to run the Csharp application in the debugger, VS2008 fails to realise that the DLL must be rebuilt (and re-copied).

我遇到的问题是,当我对DLL代码进行更改,然后尝试在调试器中运行Csharp应用程序时,VS2008无法意识到必须重建(并重新复制)DLL。

I have to force a re-build of the Csharp application (ie by explicitly choosing build, or by "touching" a .CS file).

我必须强制重新构建Csharp应用程序(即通过显式选择构建,或通过“触摸”.CS文件)。

Does anyone know how to tell Visual Studio to do the right thing? Thanks, Rob

有谁知道如何告诉Visual Studio做正确的事情?谢谢,罗布

Edits: I am using project dependencies. They aren't working correctly.

编辑:我正在使用项目依赖项。它们无法正常工作。

I am using a post-build event to copy the DLL across.

我正在使用post-build事件来复制DLL。

The issue is that, if you simply choose to debug the application, Visual Studio fails to recompile the changed C++ project, despite the fact that there is a dependency in place.

问题是,如果您只是选择调试应用程序,则Visual Studio无法重新编译已更改的C ++项目,尽管存在依赖关系。

I know the dependency is working, because if I choose "Build" (as opposed to "Debug") the C++ DLL is built.

我知道依赖是有效的,因为如果我选择“Build”(而不是“Debug”),则构建C ++ DLL。

5 个解决方案

#1


1  

"Build" and "Debug" do different things. In Tools - Options - Projects and Solutions - Build and Run, there is a checkbox "Only build startup projects and dependencies on Run". This is checked by default. So, if VS isn't recognising the DLL as a dependency, it won't build it when you choose "Debug".

“构建”和“调试”做不同的事情。在工具 - 选项 - 项目和解决方案 - 构建和运行中,有一个复选框“仅在运行时构建启动项目和依赖项”。默认情况下会选中此选项。因此,如果VS没有将DLL识别为依赖项,则在选择“Debug”时它不会构建它。

I don't have VS to hand (only Express), but you could try adding the C++ DLL as a reference rather than a dependency.

我没有VS手(只有Express),但你可以尝试添加C ++ DLL作为参考而不是依赖。

#2


0  

Hmm... so I haven't done this exact thing before but I just threw together a C++ lib project and a C# winform project in the same solution. I right-clicked the solution, chose Properties and then under Common Properties->Project Dependencies, I made the C# one depend on the C++ one.

嗯...所以我之前没有做过这个事情,但我只是在同一个解决方案中将C ++ lib项目和C#winform项目放在一起。我右键单击了解决方案,选择了Properties,然后在Common Properties-> Project Dependencies下,我使C#one依赖于C ++。

When I make a mod to the C++ one, it will ask me if I want to rebuild the C++ one. There's a "Don't ask me" checkbox too.

当我为C ++编写mod时,它会问我是否要重建C ++文件。还有一个“不要问我”复选框。

Maybe my test is different than your situation, but it seemed to work when I did that.

也许我的测试与你的情况不同,但是当我这样做时它似乎有效。

Hope that is some help.

希望这是一些帮助。

#3


0  

Assuming the DLL project isn't used in another solution, why not put the post-build event on the DLL app project, so it is always copied?

假设DLL项目没有在另一个解决方案中使用,为什么不将后期构建事件放在DLL应用程序项目上,所以它总是被复制?

#4


0  

I've not tried, but can't you do this with the build order?

我没试过,但你不能用构建顺序做这个吗?

#5


0  

I have experienced this same issue with applications that have DLL project dependencies. It seems to me that the problem is that Visual Studio only launches the post-build event if it has to recompile something in the Application's project. So, if you modify the DLL source without modifying any of the headers that the Application includes, then the Application is not recompiled because from it's perspective the DLL is the same. Since the application is not recompiled, the post-build event is not triggered. So, the Application is left with out of date DLLs. I have yet to come up with a good solution to this problem.

对于具有DLL项目依赖性的应用程序,我遇到过同样的问题。在我看来,问题是Visual Studio只有在必须重新编译应用程序项目中的某些内容时才会启动构建后事件。因此,如果您修改DLL源而不修改应用程序包含的任何标头,则不会重新编译应用程序,因为从它的角度看,DLL是相同的。由于未重新编译应用程序,因此不会触发构建后事件。因此,应用程序留下了过时的DLL。我还没有找到解决这个问题的好方法。

#1


1  

"Build" and "Debug" do different things. In Tools - Options - Projects and Solutions - Build and Run, there is a checkbox "Only build startup projects and dependencies on Run". This is checked by default. So, if VS isn't recognising the DLL as a dependency, it won't build it when you choose "Debug".

“构建”和“调试”做不同的事情。在工具 - 选项 - 项目和解决方案 - 构建和运行中,有一个复选框“仅在运行时构建启动项目和依赖项”。默认情况下会选中此选项。因此,如果VS没有将DLL识别为依赖项,则在选择“Debug”时它不会构建它。

I don't have VS to hand (only Express), but you could try adding the C++ DLL as a reference rather than a dependency.

我没有VS手(只有Express),但你可以尝试添加C ++ DLL作为参考而不是依赖。

#2


0  

Hmm... so I haven't done this exact thing before but I just threw together a C++ lib project and a C# winform project in the same solution. I right-clicked the solution, chose Properties and then under Common Properties->Project Dependencies, I made the C# one depend on the C++ one.

嗯...所以我之前没有做过这个事情,但我只是在同一个解决方案中将C ++ lib项目和C#winform项目放在一起。我右键单击了解决方案,选择了Properties,然后在Common Properties-> Project Dependencies下,我使C#one依赖于C ++。

When I make a mod to the C++ one, it will ask me if I want to rebuild the C++ one. There's a "Don't ask me" checkbox too.

当我为C ++编写mod时,它会问我是否要重建C ++文件。还有一个“不要问我”复选框。

Maybe my test is different than your situation, but it seemed to work when I did that.

也许我的测试与你的情况不同,但是当我这样做时它似乎有效。

Hope that is some help.

希望这是一些帮助。

#3


0  

Assuming the DLL project isn't used in another solution, why not put the post-build event on the DLL app project, so it is always copied?

假设DLL项目没有在另一个解决方案中使用,为什么不将后期构建事件放在DLL应用程序项目上,所以它总是被复制?

#4


0  

I've not tried, but can't you do this with the build order?

我没试过,但你不能用构建顺序做这个吗?

#5


0  

I have experienced this same issue with applications that have DLL project dependencies. It seems to me that the problem is that Visual Studio only launches the post-build event if it has to recompile something in the Application's project. So, if you modify the DLL source without modifying any of the headers that the Application includes, then the Application is not recompiled because from it's perspective the DLL is the same. Since the application is not recompiled, the post-build event is not triggered. So, the Application is left with out of date DLLs. I have yet to come up with a good solution to this problem.

对于具有DLL项目依赖性的应用程序,我遇到过同样的问题。在我看来,问题是Visual Studio只有在必须重新编译应用程序项目中的某些内容时才会启动构建后事件。因此,如果您修改DLL源而不修改应用程序包含的任何标头,则不会重新编译应用程序,因为从它的角度看,DLL是相同的。由于未重新编译应用程序,因此不会触发构建后事件。因此,应用程序留下了过时的DLL。我还没有找到解决这个问题的好方法。