1

I have a Visual Studio 2019 project with some nuget-packages. This project work very well with the build configuration Release and Debug. Now I have created my own custom build configurations. The problem is that now the project don’t link to some nuget-packages. I also found out why. When I look in *.targets file of some nuget-packages, I see something like this:

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Link>
      …
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Link>
      …
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Link>
      …
    </Link>

I think it’s no good solution to manipulate the *.targets file. So I look for a solution, that my custom build configurations inherits the Libraries form Release or Debug. Is this possible and if so how?

userName
  • 23
  • 2
  • I think you install that nuget packages for c++ projects and if you use that custom build props for include libraries into the project automatically, you should modify the targets file to add your new configuration into the condition and then it can recognize the new configuration and import them automatically. – Mr Qian May 13 '20 at 10:01

1 Answers1

-1

I think it’s no good solution to manipulate the *.targets file. So I look for a solution, that my custom build configurations inherits the Libraries form Release or Debug. Is this possible and if so how?

Actually, you can only manually add the judgment condition of the new custom Configuration in the xxx.targets file to import the lib library under the new configuration. And there is no such tool or way to let your custom build configurations inherit the Libraries form Release or Debug.

And to define a new configuration, it is itself given a new value and in proj file, it is impossible to inherit Debug or Release for a new value unless overridden.

Therefore, in XML, a single value cannot inherit the characteristics of a certain value without changing its value.

When the author himself created the package, he already identified the default Debug or Release mode and operated on them, not your new custom configuration.

So you have to modify the xxx.targets file manually.

Solution

1) add that new configuration condition into xxx.targets file manually.

If you want it be the same as Debug, you can try this:

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32' or $(Configuration)|$(Platform)'=='xxx(New Configuration)|Win32 ">
    <Link>
      …
    </Link>
  </ItemDefinitionGroup>

<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32' or $(Configuration)|$(Platform)'=='xxx(New Configuration)|x64 ">
    <Link>
      …
    </Link>
  </ItemDefinitionGroup>

I think this is quite easy and when you finish it, you should build your project under your new custom configuration to include these library path into it.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41