2

I'm using Visual Studio 2017 and CMake 3.15.4 for a C# / Windows form project, which requires a handful of external references. I set them up in the following way:

set_property(TARGET my_exe PROPERTY VS_DOTNET_REFERENCES
    ${dependency_1}
    ${dependency_2}
    ${dependency_3})

set_property(TARGET my_exe PROPERTY VS_DOTNET_REFERENCE_${dependency_1}
    "path_to_dependency_1")

...

I notice that under the Properties menu of each dependency, the property Specific Version is always set to False by default. I'm wondering how I could set it to True in CMake script to make the target use certain version of dependencies. Thanks for any pointer.

biubiuty
  • 493
  • 6
  • 17

1 Answers1

2

The documentation for VS_DOTNET_REFERENCE_<refname> here does not mention version. But, although not officially supported by CMake, it is possible to force the SpecificVersion reference property to True.

There is a great answer here documenting the situations in which the Specific Version will be checked. The check is influenced by the presence of version information in the assembly reference, and the presence of the <SpecificVersion> element. See the table reproduced here:

                            |     Version information
                            |  Present       Not present
----------------------------+------------------------------
<SpecificVersion>           |
- Present, has value True   |    Yes (1)        Yes (check always fails) (2)
- Present, has value False  |    No  (3)        No (4)
- Not present               |    Yes (5)        No (6)

Because the CMake Visual Studio generators don't provide a mechanism (yet) to set the <SpecificVersion> reference property, we have to force the Specific Version check by inserting version information along with the reference name (case 5 in the table above). Try something like this:

set_property(TARGET my_exe PROPERTY 
    "VS_DOTNET_REFERENCE_Dependency1, Version=2.1.1"
    "path_to_dependency_1"
)

This will set the version to 2.1.1, and the Specific Version reference property will be set to True, instead of the default value of False.

Kevin
  • 16,549
  • 8
  • 60
  • 74