question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet build fails for C++ projects

See original GitHub issue

I’m having an issue working with the dotnet tools and c++ projects. I initially encountered this issue using a c++ project as a reference to a C# project. However I have replicated it using a brand new c++ project in it’s own solution.

I’m probably raising this issue at the wrong part of the build chain, but any help would be greatly appreciated.

Steps to reproduce

  1. Create a new C++ Dynamic link library in Visual Studio 2019
  2. From the solution folder run dotnet build

CPlusPlusTest.zip

Expected behavior

Solution builds successfully

Actual behavior

error MSB4019: The imported project “C:\Microsoft.Cpp.Default.props” was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

It seems that the $(VCTargetsPath) variable is not being evaluated. I thought this might be just my machine having the issue, but i’m also seeing the same issue building the project in a server environment.

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

Strangely the solution builds fine from the visual studio UI

Environment data

.NET Core SDK (reflecting any global.json): Version: 2.2.203 Commit: e5bab63eca

Runtime Environment: OS Name: Windows OS Version: 6.1.7601 OS Platform: Windows RID: win7-x64 Base Path: C:\Program Files\dotnet\sdk\2.2.203\

Host (useful for support): Version: 2.2.4 Commit: f95848e524

.NET Core SDKs installed: 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.504 [C:\Program Files\dotnet\sdk] 2.1.505 [C:\Program Files\dotnet\sdk] 2.1.602 [C:\Program Files\dotnet\sdk] 2.2.103 [C:\Program Files\dotnet\sdk] 2.2.202 [C:\Program Files\dotnet\sdk] 2.2.203 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
agpreynoldscommented, Apr 30, 2019

Thanks that does make sense. So I guess I should use msbuild instead of dotnet build

Given that c++ projects are not supported do you think the error message should be a bit clearer. Something along the lines of

“The solution you are trying to build contains a C++ project. This is not supported in the dotnet CLI. Please use an appropriate version of msbuild to build the solution”

0reactions
Sewer56commented, Jul 27, 2019

Although this is not officially supported, as said. I would like to point out that this official hosting sample works around it by wrapping a C++ project around a .csproj container: https://github.com/dotnet/samples/tree/master/core/hosting/HostWithHostFxr

At the very least, for now it can serve as an idea.


Edit: For Windows users, I would like to point out that building using Visual Studio from the command line is also possible.

Consider using devenv -h from the Visual Studio Developer Command Prompt to get a list of the available flags.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet build fails on solution that with a vcproj ...
Building a solution with dotnet build fails when that solution has a C# vcproj that has a project reference to a C++/CLI vcxproj....
Read more >
Dotnet build fails for projects containing UserControl ...
Dotnet build fails for projects containing UserControl (InitializeComponent does not exist in the current context).
Read more >
Visual Studio 2022 build failed - but showing no errors
Run dotnet build -c Release inside your project folder. Clean the solution didn't help, but after building from the command line I found...
Read more >
dotnet build command - .NET CLI
The dotnet build command builds a project and all of its dependencies.
Read more >
Build in Visual Studio runs fine, msbuild fails
But when building with msbuild (locally or on DevOps) we get the following error: [error]C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found