react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

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

Open arsenikstiger opened this issue 2 years ago • 10 comments

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

arsenikstiger avatar Jul 05 '22 10:07 arsenikstiger

I tried to pass experimentalNuGetDependency to true, by following this tutorial This bug doesn't occur anymore. So I think this can be marked as a workaround.

arsenikstiger avatar Jul 06 '22 15:07 arsenikstiger

I tried to pass experimentalNuGetDependency to true, by following this tutorial This bug doesn't occur anymore. So I think this can be marked as a workaround.

Glad you're unblocked. Requiring that you use the experimental nuget and not be able to build from source may not work for everyone. So there's still a gap here.

chrisglein avatar Jul 07 '22 18:07 chrisglein

This could be related to RNW's enablement of PackageReference for C++ NuGet dependencies. I will investigate in depth tomorrow.

JunielKatarn avatar Jul 14 '22 18:07 JunielKatarn

Hi @arsenikstiger.

Can you please specify what PInvoke NuGet package did you add? There doesn't seem to be a package with that exact name in nuget.org.

JunielKatarn avatar Jul 15 '22 20:07 JunielKatarn

Following the mentioned steps but adding NuGet dependency PInvoke.Windows.Core, the issue does not reproduce. image

JunielKatarn avatar Jul 15 '22 20:07 JunielKatarn

I'm also trying to create a react-native windows with c#. Just like the OP, if I go through the steps on the getting started page and never open the visual studio solution, the app starts. However, if I open the visual studio solution (I did NOT change any of the code) and try to run "npx react-native run-windows", I also get the following:

× Building Solution: C:[path to project]\node_modules\react-native-window... × Build failed with message C:[path to project]\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' attribute [C:[path to project]\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\Microsoft.ReactNative.Managed.CodeGen.csproj]. Check your build configuration.

In addition, this sequence:

npx react-native init <projectName> --template react-native@^0.69.0 cd projectName npx react-native-windows-init --overwrite --language cs npx react-native autolink-windows (this one says that it doesn't need to do any linking) (opening the VS solution, setting the configuration to debug x64) yarn start start without debugging from VS

gives the following build failed error from visual studio

Error Could not write lines to file "build\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\netcoreapp3.1\win-x64\Microsoft.ReactNative.Managed.CodeGen.GeneratedMSBuildEditorConfig.editorconfig". Could not find a part of the path '[path to project]\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\build\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\netcoreapp3.1\win-x64\Microsoft.ReactNative.Managed.CodeGen.GeneratedMSBuildEditorConfig.editorconfig'. [name of project]

My version info:

windows 10.0.19043

Microsoft Visual Studio Community 2019 Version 16.11.17 VisualStudio.16.Release/16.11.17+32630.194 Microsoft .NET Framework Version 4.8.04084 Installed Version: Community Visual C++ 2019 00435-00000-00000-AA918 Microsoft Visual C++ 2019

react-native - 0.69.0 node - v14.18.1

EDIT - The 1st and 2nd issue I printed above were fixed by moving my project location closer to root. I had a hunch that the path was getting too long. I noted the "enable long path support" in the "likely out of date" instruction before I started and looked this up and changed a value in the registry. Did I not do this correctly? I have no way of knowing. Can someone tell me a workaround or the correct way to 'enable long path support', I'd like to not have to name my projects without vowels and place them right on the C drive, lol.

jmurp avatar Jul 16 '22 21:07 jmurp

I want to upgrade my app from 0.65 to 0.69 and i always do working Hello World app before upgrade to see all needed changes.

I tried to build React Native Windows Hello World app on 0.69.3 and i get about the same build errors.

Steps to create C# HelloWorld 0.69.3. I ran these command in root to prevent paths to get too long.

npx react-native init Hello069 --template [email protected]
cd Hello069
yarn install
npx react-native-windows-init --overwrite --language cs --version 0.69.4

I opened solution file by Visual Studio 2019 (16.11.6) and tried x64 debug build (Build->Build solution).

I get assembly build errors:

8>C:\Users\tepaa\Hello069\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,4,70): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute
8>C:\Users\tepaa\Hello069\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\build\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\netcoreapp3.1\win-x64\Microsoft.ReactNative.Managed.CodeGen.AssemblyInfo.cs(14,12,14,54): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute
8>C:\Users\tepaa\Hello069\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\build\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\netcoreapp3.1\win-x64\Microsoft.ReactNative.Managed.CodeGen.AssemblyInfo.cs(15,12,15,60): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute
8>C:\Users\tepaa\Hello069\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\build\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\netcoreapp3.1\win-x64\Microsoft.ReactNative.Managed.CodeGen.AssemblyInfo.cs(16,12,16,58): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute
8>C:\Users\tepaa\Hello069\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\build\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\netcoreapp3.1\win-x64\Microsoft.ReactNative.Managed.CodeGen.AssemblyInfo.cs(17,12,17,67): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute
8>C:\Users\tepaa\Hello069\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\build\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\netcoreapp3.1\win-x64\Microsoft.ReactNative.Managed.CodeGen.AssemblyInfo.cs(18,12,18,54): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute
8>C:\Users\tepaa\Hello069\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\build\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\netcoreapp3.1\win-x64\Microsoft.ReactNative.Managed.CodeGen.AssemblyInfo.cs(19,12,19,52): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute
8>C:\Users\tepaa\Hello069\node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\build\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\netcoreapp3.1\win-x64\Microsoft.ReactNative.Managed.CodeGen.AssemblyInfo.cs(20,12,20,54): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute

Warning

Severity	Code	Description	Project	File	Line	Suppression State
Warning		The project 'Microsoft.ReactNative' cannot be referenced. The referenced project is targeted to a different framework family (native)	Hello069			
System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Memory: 21.35 GB / 31.90 GB
  Binaries:
    Node: 14.20.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      AllowAllTrustedApps: Enabled
      Versions: 10.0.18362.0, 10.0.19041.0
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.11.31829.152 (Visual Studio Community 2019)
  Languages:
    Java: Not Found
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: 0.69.3 => 0.69.3
    react-native-windows: 0.69.4 => 0.69.4
  npmGlobalPackages:
    *react-native*: Not Found

tero-paananen avatar Aug 01 '22 11:08 tero-paananen

RNW 0.68 C# HelloWorld builds without errors

npx react-native init Hello068 --template [email protected]
cd Hello068
yarn install
npx react-native-windows-init --overwrite --language cs --version 0.68.12

tero-paananen avatar Aug 01 '22 11:08 tero-paananen

Solution for this error (in 0.69) is maybe something

  • https://developercommunity.visualstudio.com/t/duplicate-globalsystemruntimeversioningtargetframe/1055833
  • https://stackoverflow.com/questions/61997928/errorcs0579duplicate-globalsystem-runtime-versioning-targetframeworkattribu

tero-paananen avatar Sep 08 '22 09:09 tero-paananen

I managed first time to build 0.69.6 C# HelloWorld on Visual Studio 2019 (x64 Debug) without duplicate errors for example

"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."

by adding these lines

<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> 

into node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\Microsoft.ReactNative.Managed.CodeGen.csproj

BUT some challenges with the release build...it is white screen. White screen bug may be fixed on RNW 0.70 and will come later on 0.69...

My C# HelloWorld app for test this issue

npx react-native init Hello069 --template [email protected]
cd Hello069
yarn install
npx react-native-windows-init --overwrite --language cs --version 0.69.6

C++ version of the HelloWorld app builds without errors.

tero-paananen avatar Sep 08 '22 11:09 tero-paananen

I am having the same issue. Rolling back to 0.68 did indeed work. Are there any fixes for newer versions already?

daanlenaerts avatar Oct 10 '22 14:10 daanlenaerts

I'm also seeing this after upgrading from 0.68.0 to 0.69.0. Is there any guidance on this?

haightt avatar Oct 12 '22 18:10 haightt

I'm also seeing this after upgrading from 0.68.0 to 0.69.0. Is there any guidance on this?

Above is my solution

https://github.com/microsoft/react-native-windows/issues/10236#issuecomment-1240577791

tero-paananen avatar Oct 12 '22 19:10 tero-paananen

I'm also seeing this after upgrading from 0.68.0 to 0.69.0. Is there any guidance on this?

Above is my solution

#10236 (comment)

Thank you for the workaround, but you also mentioned "BUT some challenges with the release build...it is white screen.", so I assume this is still a problem?

daanlenaerts avatar Oct 12 '22 19:10 daanlenaerts

I'm also seeing this after upgrading from 0.68.0 to 0.69.0. Is there any guidance on this?

Above is my solution #10236 (comment)

Thank you for the workaround, but you also mentioned "BUT some challenges with the release build...it is white screen.", so I assume this is still a problem?

Not anymore white screen issue with latest 0.69 version on release build

tero-paananen avatar Oct 12 '22 19:10 tero-paananen

Where specifically did you put those lines of code? Your answer is not very specific

haightt avatar Oct 12 '22 19:10 haightt

Where specifically did you put those lines of code? Your answer is not very specific

node_modules\react-native-windows\Microsoft.ReactNative.Managed.CodeGen\Microsoft.ReactNative.Managed.CodeGen.csproj

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>

    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Platforms>x64;x86;ARM;ARM64</Platforms>
    <RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>

    <Platform>x64</Platform>
    <!-- We are a tool, so on all platforms force win-x64 -->
    <PlatformTarget>x64</PlatformTarget>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>

    <Nullable>enable</Nullable>
    <LangVersion>8.0</LangVersion>

    <! -- TO GET 0.69 C# APP BUILD -->
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>  
    
  </PropertyGroup>
  ...

tero-paananen avatar Oct 13 '22 06:10 tero-paananen

but i of course hope that some in Microsoft gives validated fix for this issue

tero-paananen avatar Oct 13 '22 06:10 tero-paananen

Let's hope so. Thank you for your help @tero-paananen!

daanlenaerts avatar Oct 13 '22 07:10 daanlenaerts

@chrisglein @JunielKatarn, Can we get any insight on this issue? I do not see this every time I attempt a release build. For example, I just restarted my machine and ran npx react-native run-windows --release, and my app was built successfully. I kill the app, open Visual Studio 2022, run npx react-native run-windows --release, and then run into the error.

haightt avatar Oct 13 '22 13:10 haightt

@haightt Can you share the sources/branch you are working on to try and follow the same exact steps?

This looks like a very particular corner case.

JunielKatarn avatar Oct 14 '22 00:10 JunielKatarn

I cannot. This is happening attempting to upgrade our company's app.

haightt avatar Oct 28 '22 19:10 haightt

@JunielKatarn Now I am getting this in Visual Studio image

haightt avatar Oct 28 '22 21:10 haightt

@haightt would you be willing to share a binary build log privately?

If so, please follow these steps:

MSBuild.exe <your solution> /t:Restore '/p:RestoreProjectStyle=PackagesConfig;RestorePackagesConfig=true' /bl:pkgcnf.binlog

MSBuild.exe <your solution> /restore /bl:pkgref.binlog

This should generate two .binlog files: pkgcnf.binlog and pkgref.binlog.

JunielKatarn avatar Oct 28 '22 22:10 JunielKatarn

@JunielKatarn Now I am getting this in Visual Studio image

My solution for this error was define for example <WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion> into ExperimentalFeatures.props file.

Idea for this is force all modules to use same versions (target, min, max target platform version).

Clean and rebuild all...

tero-paananen avatar Oct 29 '22 03:10 tero-paananen

@JunielKatarn I was able to generate the .binlog file from the second command. However, the first results in the error MSB1008: Only one project can be specified

haightt avatar Dec 28 '22 19:12 haightt

@haightt there is likely more than one project or solution file in that directory (.vcxproj, .csproj, .sln). Please try again using the specific project file you want to log as a command argument.

JunielKatarn avatar Dec 29 '22 00:12 JunielKatarn

@JunielKatarn, I was able to generate both of those files. How would you like me to share them with you?

haightt avatar Dec 29 '22 19:12 haightt

@haightt

Please do.

JunielKatarn avatar Dec 29 '22 21:12 JunielKatarn

I created a basic new react-native-windows app and ran into the same issue when performing a release build. I am confused as to what is going on here. I did this to eliminate the possibility that one of the packages we use is causing the build issue. Here's what I did:

  1. Followed the steps to create a new app here: https://microsoft.github.io/react-native-windows/docs/getting-started. I added the --language cs flag to create a C# windows app.
  2. Ran npx react-native run-windows. This was built successfully, and I got the boilerplate starting screen.
  3. Run npx react-native run-windows --release. This fails with the global::System.Runtime.Versioning.TargetFrameworkAttribute error.
  4. I then try to run the debug build again using npx react-native run-windows. This now fails with the duplicate framework error.

Here is the repo for that bare app: https://github.com/haightt/RNW070. I don't know how helpful that is, as I didn't change any code here; I just initialized the app.

haightt avatar Jan 04 '23 20:01 haightt