2

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? :(

5
  • 1
    If it was me, I'd create a new project and build it up step by step to resemble the old one until I could identify what was different. Commented Aug 16, 2020 at 6:17
  • github.com/dotnet/sdk/issues/1321 Commented Aug 16, 2020 at 8:59
  • delete obj/bin folders and try again Commented Aug 16, 2020 at 12:46
  • the following build order help me out: git clean -xfd, nuget restore $sln, dotnet restore $sln, msbuild $sln Commented Oct 16, 2020 at 4:58
  • presumably you figured this out. please post your conclusion in an answer Commented Apr 29, 2021 at 16:12

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

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!!!

Comments

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 

Comments

0

I ended up here after a Google search. But I didn't find my answer here.

Instead, in my publish profile I needed to choose the x64 configuration. And when I did it worked.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.