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 issueHello. 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:
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:
- Created 2 years ago
- Reactions:3
- Comments:13 (3 by maintainers)
Top GitHub Comments
Another thing to note is that the item group with the
KnownAppHostPack
item update needs to come after the import ofMicrosoft.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.
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.