Hello,
I have a solution that contains some C++/Cli projects, and doing a ngbv install breaks nuget restore when run from the command line.
##[error]The nuget command failed with exit code(1) and error(NU1201: Project MyCliProject is not compatible with net462 (.NETFramework,Version=v4.6.2). Project MyCliProject supports: native (native,Version=v0.0)
The issue is that Directory.Build.props adds a ProjectReference for all project types. This fails as the project type is technically "native" for C++/Cli.
I found I can fix this issue my adding a condition to the PackageReference ItemGroup:
<ItemGroup Condition="'$(PlatformToolset)' == ''">
<PackageReference Include="Nerdbank.GitVersioning">
<Version>3.3.37</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
This works since C# projects do not define a PlatformToolset as the C++/Cli projects do.
I would create a PR, but I am unsure if this is a generic enough fix for all supported project types. Your thoughts?
Tristan
Thanks for the report and the suggested workaround.
Actually though, we do expect this package to work for C++ projects so I'm surprised to see this failure. NB.GV actually creates version.rc files for C++ binaries.
Can you perhaps create a minimal repro and share?
Sure, you can access a bare-bones repo here.
If you clone, simply do a nuget retore CppCliFailureNBGC.sln
It will appear to succeed, however you'll note boost (which is installed in packages.config) isn't downloaded. Note that packages.config is the only option supported by C++/Cli projects since they are "native" targets.
Perhaps we can key off
<CLRSupport>true</CLRSupport>
I believe this value can also be netcore for some C++/Cli projects.
Thanks for the quick fix! Unfortunately, I've uncovered more. I've pushed new code to the same repository.
It appears this occurs when any project is utilizing packages.config.
nuget retore CppCliFailureNBGC.sln still fails even when there's just a .NET Framework class library. If you'd like to see the failure, checkout 5ffdf950809a2a8afe43803487ed6484af4d9562
I found the following has fixed it and avoids intermixing PackageReferences when packages.config is used (C++/Cli, C#, or otherwise). I made it the last commit in the repo.
<ItemGroup Condition="!Exists('packages.config')">
<PackageReference Include="Nerdbank.GitVersioning">
<Version>3.3.37</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Thanks. I suppose we should combine this with the previous condition you suggested earlier so that it doesn't break vcxproj builds that don't have a packages.config file either, right?
Actually, I don't believe so.
It only happens when mixing the PackageReference and packages.config styles in a project, whether it be C#, C++/Cli, or native C++. According to this, PackageReference isn't supported on JavaScript and certain ASP.NET projects either. This should fix those cases also, although I have no experience with those types.
Checking for packages.config should be all that's necessary, at least for the nuget restore.
I tried the Condition="!Exists('packages.config')" version in a few large solutions which have a mix of C++, C++/Cli, and C# and it worked well.
I've changed the PR to just that new simple condition then. Thank you.