1

After I upgrade my project files to new project file format, my executable client project (.exe) throw the error when I compile it with msbuild:

error NETSDK1047: Assets file obj\project.assets.json doesn't have a target ".NETFramework,Version=v4.8/win7-x86". Make sure that the restore has been performed and that you have included "net48" in the TargetFrameworks for your project. You may also have to include "win7-x86" in the RuntimeIdentifiers of your project.

I upgrade a lot of projects but only the executable client project make some trouble, the rest works fine.

Old .vbproj Format (header only):

The format I used before look like:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{1187BEA1-xxxx-43CF-xxxx-0C142F0A16FC}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <MyType>WindowsForms</MyType>
    <RootNamespace>MyNamespace</RootNamespace>
    <AssemblyName>MyAssemblyName</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <OptionExplicit>On</OptionExplicit>
    <OptionCompare>Binary</OptionCompare>
    <OptionStrict>On</OptionStrict>
    <OptionInfer>On</OptionInfer>
    <ApplicationIcon>MyIcon.ico</ApplicationIcon>
    <RestorePackages>true</RestorePackages>
  </PropertyGroup>

New .vbproj Format (header only):

The format I upgrade to looks like:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <RootNamespace>MyRootNamespace</RootNamespace>
    <AssemblyName>MyAssemblyName</AssemblyName>
    <Deterministic>false</Deterministic>
    <TargetFramework>net48</TargetFramework>
    <OutputPath>$(SolutionDir)bin\$(Configuration)\</OutputPath>
    <OutputType>WinExe</OutputType>
    <ApplicationIcon>MyIcon.ico</ApplicationIcon>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <OptionStrict>On</OptionStrict>
    <StartupObject>Program</StartupObject>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

What I Try?

  • Like the exception suggest, I add <RuntimeIdentifier>win7-x86</RuntimeIdentifier> to my executable client project. I have know idea why the compiler expect win7-x86 here. I am working on a win10 machine. I perform gt clean -xfd to get rid of the obj folders, but nothing changed, same exception.

  • I use dotnet restore my.sln instead of nuget restore

More Information:

  • I am not really sure whether the <StartupObject>Program</StartupObject> combined with <OutputType>WinExe</OutputType> is enough for a executable client project. Is that state of the art?

  • Another weird thing is, that the first compilings works totally fine. After a few times the mentioned exception occurs. The exception can also be solved by a full machine reboot, but I can't reboot my machine after each compile.

  • The exception (NETSDK1047) get thrown by the Microsoft.PackageDependencyResolution.targets (full path: C:\Program Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5))

  • I restore my solution dependencies and packages with nuget restore my.sln

So what can I do here? :(

Mar Tin
  • 2,132
  • 1
  • 26
  • 46

3 Answers3

2

Anyone who ends up here from Google, I tracked down the issue to the NuGetRestore MSBuild community task. This is what we were doing to restore packages:

<Target Name="Restore">
  <NuGetRestore Solution="TestApp.sln"/>
</Target>

Instead of using that, I let the MSBuild task itself do the restore:

<Target Name="BuildSolution">
  <MSBuild Projects="TestApp.sln" Properties="Platform=x64" Targets="Restore;Build" />
</Target>

Notice the Targets. I think this issue showed up as soon as we started mixing SDK-style and old style csproj project file formats.

Shahin Dohan
  • 6,149
  • 3
  • 41
  • 58
1

Builds fine on my machine. Why not my CI pipeline?

So I had converted my tiny csproj winform project from old school format to SDK format by building it from the ground up but also got this error.

Here was my starting place:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFrameworks>net48;netcoreapp3.1;net50-windows</TargetFrameworks>
    <UseWindowsForms>true</UseWindowsForms>
    <ApplicationManifest>app.manifest</ApplicationManifest>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net48|AnyCPU'">
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\Ross.Utilities.Crypto\Ross.Utilities.Crypto.csproj" />
  </ItemGroup>

</Project>

I got to looking at my Azure CI pipeline and realized it was targeting a BuildConfiguration of Release - so I added a new PropertyGroup so I could properly target Release|net48|AnyCPU

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFrameworks>net48;netcoreapp3.1;net50-windows</TargetFrameworks>
    <UseWindowsForms>true</UseWindowsForms>
    <ApplicationManifest>app.manifest</ApplicationManifest>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net48|AnyCPU'">
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net48|AnyCPU'">
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\Ross.Utilities.Crypto\Ross.Utilities.Crypto.csproj" />
  </ItemGroup>

</Project>

Now I'm all GOOD!!!

bkwdesign
  • 1,953
  • 2
  • 28
  • 50
0

indeed i have issue since migration to SDK style csproj : my solution is mixed with old legacy and new SDK style csproj.

my solution is: Install sdk version you need Download nuget.exe https://learn.microsoft.com/en-us/nuget/install-nuget-client-tools

run the 2 restore in series:

nuget restore  $PROJECT_NAME.sln -ConfigFile ${CI_COMMON_DIR}\NuGet.Config 
dotnet restore  $PROJECT_NAME.sln 
Thierry Brémard
  • 625
  • 1
  • 5
  • 14