microsoft / microsoft/react-native-windows

duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' when launching run-windows

Open
#10,236 46 comments 0 reactions 1 assignee View on GitHub

@JunielKatarn is already working on this.

Since Jul 14, 2022.

Area: Build Infrastructure bug PackageReference Workstream: ES Compliance SFI
Dominant language
C++
Stars
17.3k
Forks
1.2k
Avg merge
1d 13h
Merged PRs (30d)
33

Description

Problem Description

I created a project by following instructions on get-started for react-native for windows, and choosed C#.
I created the project today, so I use the last version.
The 1st start of the project was good.

But as soon as I modifiy the .NET project to include my own code and nuget dependencies (PInvoke), I encounter this problem when building my project with react-native run-windows command:

Build failed with message 9:6>[project-path]\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\build\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\netcoreapp3.1\win-x64.NETCoreApp,Version=v3.1.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' [[project-path]\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\Microsoft.ReactNative.Managed.CodeGen.csproj]. Check your build configuration.

I tried to clean the project from VS2022, but no results.

Steps To Reproduce
  1. Create react-native for windows project with C#
  2. Open project sln with Visual Studio 2022
  3. Add some code and include a nuget dependency (PInvoke in my case)
  4. Run npx react-native run-windows
Expected Results

It has to build and launch my project !

CLI version

8.0.2

Environment
Languages:
    Java: javac 17 - C:\Program Files\Eclipse Foundation\jdk-17.0.0.35-hotspot\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.0.0 => 18.0.0
    react-native: 0.69.0 => 0.69.0
    react-native-windows: ^0.69.1 => 0.69.1
  npmGlobalPackages:
    *react-native*: Not Found
Target Platform Version

10.0.19041

Target Device(s)

Desktop

Visual Studio Version

Visual Studio 2022

Build Configuration

Debug

Snack, code example, screenshot, or link to a repository

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.