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.

NETSDK1145: 'The Apphost pack is not installed' error while building C++\CLI project (targeting .NET 5) with Visual Studio 2019 16.11.1 if Visual Studio 2022 17.0.0 Preview 3.1 is installed

See original GitHub issue

Hello. I have C++\CLI project (targeting .NET 5) that was building correctly with latest Visual Studio 2019 16.11.1 yesterday. Today I’ve installed Visual Studio 2022 17.0.0 Preview 3.1 (than includes .NET 6 preview 7). And today I cannot build my project:

C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkRefere nceResolution.targets(127,5): NETSDK1145: The Apphost pack is not installed and NuGet package restore is not supported. Upgrade Visual Studio, remove global.json if it specifies a certain SDK version, and uninstall the newer SDK. For more options visit https://aka.ms/targeting-apphost-pack-missing Pack Type: Apphost, Pack directory: C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Host.win-x86, targetframework: net5.0, Pack PackageId: Microsoft.NETCore.App.Host.win-x86, Pack Package Version: 5.0.8.

Strange thing is that now C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Sdks\Microsoft.NET.Sdk is used to build my C++\CLI project (targeting .NET 5)…

In C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Host.win-x86 the following folders are present: image

Adding this to MyProject.vcxproj (as recommended at https://aka.ms/targeting-apphost-pack-missing) changes nothing:

<ItemGroup>
  <KnownAppHostPack Update="@(KnownAppHostPack)">
    <AppHostPackVersion Condition="'%(TargetFramework)' == 'TARGETFRAMEWORK'">5.0.9</AppHostPackVersion>
  </KnownAppHostPack>
</ItemGroup>

.NET SDK 5.0.8 refuses to install because a newer version (5.0.9) alsready present in my system.

Any help is appreciated.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
elinor-fungcommented, Aug 26, 2021

Another thing to note is that the item group with the KnownAppHostPack item update needs to come after the import of Microsoft.Cpp.targets (at the bottom of the project for a new vcxproj).

Using a Directory.Build.targets could help with sharing across all projects.

I just hit this issue myself (on a simple solution), so I’m just commenting based on my experience applying the workaround. Definitely not familiar enough with the SDK or how it integrates with VS - so I’ll leave your questions for folks like @marcpopMSFT and @wli3.

1reaction
marcpopMSFTcommented, Sep 9, 2021

Basically, this is a problem when installing previews along with the prior version. In this case, VS 2022 came with the 6.0 SDK which included an implicit reference to the 5.0.8 runtime. VS 2019 will automatically pick up that SDK and lead to you having 5.0.9 installed (which works for most scenarios as we use nuget package restore for many other scenarios but we can’t for c++/CLI so it gets impacted most). Our preview SDKs are done in public so don’t include the latest runtimes (which can contain security fixes so are prepared internally) for downlevel targeting.

Besides the directory.build.props option, you can also use a global.json to force it to use the 5.0 SDK. I normally don’t recommend global.json (as there can be unexpected side-effects to doing so) as typically we encourage using the newest shipped SDK but in this case, it’s a preview.

If you only build in VS, you can also disable the checkbox in VS 2019 to load preview SDKs (search for preview features under the tools options menu) so VS 2019 will then not load the 6.0 preview SDK. The command line will still automatically choose the most recent SDK though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NETSDK1145: Targeting or apphost pack missing - .NET CLI
When the .NET SDK issues error NETSDK1145, the targeting or apphost pack is not installed and NuGet package restore is not supported.
Read more >
Started to get "This project is targeting a version of .NET ...
I'm getting this same issue with ASP.Net Core 3.1. The solution has been fine for two years and now it want's to install...
Read more >
Solution to Visual Studio 2022 messing up ...
The error shown when attempting to load the projects was: The project file cannot be opened. Unable to locate the .NET SDK. Check...
Read more >
The SDK 'Microsoft.NET.Sdk' specified could not be found. ...
Since Visual Studio 2022 updated from version 17.4 to 17.5, I couldn't load my project. and get the error "The SDK 'Microsoft.NET.
Read more >
Microsoft Visual Studio 2019: The project file cannot be ...
I just upgraded my visual studio 2019 to latest version 16.8.3 and suddenly I am not able to load any C# project and...
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