My C# program uses a COM component via an interop assembly. The COM component sometimes changes (methods are added at the end of interface). I need to build this program in an automated build and have the interop assembly incrementing its version number – this can be achieved by using tlbimp as a pre-build step.
The problem is that the reference in the project file is set to some specific version (say 4.0.0.34) – the one which the interop assembly had when the reference was added. Once the number is incremented by an automated build and the pre-build step is done the version number store in the project file no longer matches the number in the assembly properties and I get
warning MSB3245: Could not resolve this reference. Could not locate the assembly “Interop.MyCOMComponent, Culture=neutral, Version=4.0.0.34, processorArchitecture=MSIL”. Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
and then
The type or namespace name ‘MyCOMComponent’ could not be found (are you missing a using directive or an assembly reference?)
Can I somehow tell Visual Studio that I don’t want to store the exact assembly version inside the project file and it should use whatever version it sees at compile time?
The thing that worked for me was to remove the “COM” reference and add the reference to the interop assembly as if it was a normal “.NET” reference. Since the latter doesn’t store a version number the problem got solved once and for all.