简体   繁体   中英

MSBuild Build same DLL with two different projects

I have a system that uses an external COM component. There are two different versions of the COM object that are basically the same (The vendor changed the COM GUID without an interface change.) I use tlbimp.exe to make two interop DLL's that are basically the same one for each COM object. I want to build two .NET dll's of the same assemble name one for each COM object. So I have two different projects that reference all the same C# source code (Add as Link). The only difference is a different reference to the interop DLL. The plan was to end up with to different DLL's that are basically the same (one for each COM object) and then rename the one that is needed at install time.

I started with a different bin directory for the second DLL built. However the build process is set to single bin dir (TFS Output Location=Single Folder) which causes the second DLL to overwrite the first. So I added a post build script to rename each DLL as it's built.

The next problem is that the rename prevents downstream code from compiling. (missing assembly errors) I could try and pick the first DLL build and keep it around with the original name but I can see scenarios when built locally that would end with confusion. Which COM object is the one in use. Basically, build errors could leave the system in a weird state.

I originally looked to see if I could build a DLL with it's filename different from the internal assembly name but that doesn't seem possible.

Two thoughts on a solution: (Maybe there's another?)

1) Can I build a .NET DLL with the filename different from the AssemblyName? OR

2) What is a clean way to rename / copy the build out of one (or both) dll AND preserve one of them for dependent code building?

What I ended up doing was to split out the second DLL into another solution and make another entry in the TFS Process / Build / Projects

In the second project's pre-build step I needed to rename the first DLL so that the second project would build with the same dll name. Then in the post-build step I renamed the new DLL to it's special name and renamed the first DLL back to the original name.

I felt this was the cleanest way to handle the issue. TFS Build ensures that this second solution / project is built in sequential order.

In the single solution concept, I had played around with renaming in the Pre / Post build events of the projects but discovered that they aren't as sequential / ordered as you might thing. See this post for more details:

MSbuild build order issue - pre-build steps first or dependent projects first

I didn't want to manually edit the csproj XML because we don't have many on the team that are comfortable with such edits. Thus the second solution to the build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM