Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

C# TargetFrameworkVersion v4.5 throws error

Discussion in 'Scripting' started by Nit_Ram, Dec 21, 2018.

  1. Nit_Ram

    Nit_Ram

    Joined:
    May 8, 2016
    Posts:
    27
    Hello there!

    I'm experiencing a strange behaviour of Unity (is it a bug?):
    When I create a new project in Unity 2018.3.02f, the Assembly-CSharp-Editor.csproj has the TargetFrameworkVersion set to v4.5.

    1.jpg

    According to the official Microsoft documentation v4.5 is not a supported TargetFrameworkVersion (https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-target-framework-and-target-platform).
    This throws me an error when opening the project in Visual Studio Code.

    3.jpg
    (For Error Log see end of post)

    When I try to change the version manually to e.g. v4.5.2, it works, until I restart Unity. Unity will then reset it to 4.5.

    I installed the latest .NET Framework (.NET Core 2.2 and .NET Framework 4.7.2) and the latest Visual Studio Code Version with the latest C#-Extension.
    Also tried to open the project in Visual Studio (not Code), where it gives me the same error.


    Am I doing something wrong or is Unity really using a not supported Framework version?

    btw, I'm on Windows 10, so it can't be a problem of Mono, right?

    My Player Project Settings:
    2.jpg

    Error Log: (sorry, it's in German, couldn't find out how to change the language of Omnisharp Log)
    It basically says: "The target framework version for .NETFramework,Version=v4.5 couldn't be found. Please install the SDK, blahblah"

    Code (csharp):
    1. Starting OmniSharp server at 12/21/2018, 1:10:54 PM
    2.     Target: f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\BF_Prototyp_1.sln
    3.  
    4. OmniSharp server started.
    5.     Path: C:\Users\Martin Matthias\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\OmniSharp.exe
    6.     PID: 18140
    7.  
    8. [info]: OmniSharp.Stdio.Host
    9.         Starting OmniSharp on Windows 6.2.9200.0 (x64)
    10. [info]: OmniSharp.Services.DotNetCliService
    11.         DotNetPath set to dotnet
    12. [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
    13.         Located 2 MSBuild instance(s)
    14.             1: Visual Studio Community 2017 15.9.28307.222 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"
    15.             2: StandAlone 15.0 - "C:\Users\Martin Matthias\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin"
    16. [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
    17.         Registered MSBuild instance: Visual Studio Community 2017 15.9.28307.222 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"
    18. [info]: OmniSharp.Cake.CakeProjectSystem
    19.         Detecting Cake files in 'f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1'.
    20. [info]: OmniSharp.Cake.CakeProjectSystem
    21.         Could not find any Cake files
    22. [info]: OmniSharp.WorkspaceInitializer
    23.         Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
    24. [info]: OmniSharp.MSBuild.ProjectSystem
    25.         Detecting projects in 'f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\BF_Prototyp_1.sln'.
    26. [info]: OmniSharp.MSBuild.ProjectManager
    27.         Queue project update for 'f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-firstpass.csproj'
    28. [info]: OmniSharp.MSBuild.ProjectManager
    29.         Queue project update for 'f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-Editor-firstpass.csproj'
    30. [info]: OmniSharp.MSBuild.ProjectManager
    31.         Queue project update for 'f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-Editor.csproj'
    32. [info]: OmniSharp.Script.ScriptProjectSystem
    33.         Detecting CSX files in 'f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1'.
    34. [info]: OmniSharp.MSBuild.ProjectManager
    35.         Loading project: f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-firstpass.csproj
    36. [info]: OmniSharp.Script.ScriptProjectSystem
    37.         Could not find any CSX files
    38. [info]: OmniSharp.WorkspaceInitializer
    39.         Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
    40. [info]: OmniSharp.WorkspaceInitializer
    41.         Configuration finished.
    42. [info]: OmniSharp.Stdio.Host
    43.         Omnisharp server running using Stdio at location 'f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1' on host 16620.
    44. [fail]: OmniSharp.MSBuild.ProjectLoader
    45.         Die Verweisassemblys für Framework ".NETFramework,Version=v4.5" wurden nicht gefunden. Installieren Sie zum Beheben dieses Problems das SDK oder das Paket zur Festlegung von Zielversionen für die vorliegende Frameworkversion, oder legen Sie als neues Ziel für die Anwendung eine Version des Frameworks fest, für die Sie das SDK oder Paket zur Festlegung der Zielversionen installiert haben. Assemblys werden im globalen Assemblycache (GAC) aufgelöst und anstelle von Verweisassemblys verwendet. Daher wird die Assembly für das gewünschte Framework unter Umständen nicht ordnungsgemäß als Ziel festgelegt.
    46. [warn]: OmniSharp.MSBuild.ProjectManager
    47.         Failed to load project file 'f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-firstpass.csproj'.
    48. f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-firstpass.csproj
    49. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1179,5): Error: Die Verweisassemblys für Framework ".NETFramework,Version=v4.5" wurden nicht gefunden. Installieren Sie zum Beheben dieses Problems das SDK oder das Paket zur Festlegung von Zielversionen für die vorliegende Frameworkversion, oder legen Sie als neues Ziel für die Anwendung eine Version des Frameworks fest, für die Sie das SDK oder Paket zur Festlegung der Zielversionen installiert haben. Assemblys werden im globalen Assemblycache (GAC) aufgelöst und anstelle von Verweisassemblys verwendet. Daher wird die Assembly für das gewünschte Framework unter Umständen nicht ordnungsgemäß als Ziel festgelegt.
    50.  
    51. [info]: OmniSharp.MSBuild.ProjectManager
    52.         Loading project: f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-Editor-firstpass.csproj
    53. [fail]: OmniSharp.MSBuild.ProjectLoader
    54.         Die Verweisassemblys für Framework ".NETFramework,Version=v4.5" wurden nicht gefunden. Installieren Sie zum Beheben dieses Problems das SDK oder das Paket zur Festlegung von Zielversionen für die vorliegende Frameworkversion, oder legen Sie als neues Ziel für die Anwendung eine Version des Frameworks fest, für die Sie das SDK oder Paket zur Festlegung der Zielversionen installiert haben. Assemblys werden im globalen Assemblycache (GAC) aufgelöst und anstelle von Verweisassemblys verwendet. Daher wird die Assembly für das gewünschte Framework unter Umständen nicht ordnungsgemäß als Ziel festgelegt.
    55. [warn]: OmniSharp.MSBuild.ProjectManager
    56.         Failed to load project file 'f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-Editor-firstpass.csproj'.
    57. f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-Editor-firstpass.csproj
    58. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1179,5): Error: Die Verweisassemblys für Framework ".NETFramework,Version=v4.5" wurden nicht gefunden. Installieren Sie zum Beheben dieses Problems das SDK oder das Paket zur Festlegung von Zielversionen für die vorliegende Frameworkversion, oder legen Sie als neues Ziel für die Anwendung eine Version des Frameworks fest, für die Sie das SDK oder Paket zur Festlegung der Zielversionen installiert haben. Assemblys werden im globalen Assemblycache (GAC) aufgelöst und anstelle von Verweisassemblys verwendet. Daher wird die Assembly für das gewünschte Framework unter Umständen nicht ordnungsgemäß als Ziel festgelegt.
    59.  
    60. [info]: OmniSharp.MSBuild.ProjectManager
    61.         Loading project: f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-Editor.csproj
    62. [fail]: OmniSharp.MSBuild.ProjectLoader
    63.         Die Verweisassemblys für Framework ".NETFramework,Version=v4.5" wurden nicht gefunden. Installieren Sie zum Beheben dieses Problems das SDK oder das Paket zur Festlegung von Zielversionen für die vorliegende Frameworkversion, oder legen Sie als neues Ziel für die Anwendung eine Version des Frameworks fest, für die Sie das SDK oder Paket zur Festlegung der Zielversionen installiert haben. Assemblys werden im globalen Assemblycache (GAC) aufgelöst und anstelle von Verweisassemblys verwendet. Daher wird die Assembly für das gewünschte Framework unter Umständen nicht ordnungsgemäß als Ziel festgelegt.
    64. [warn]: OmniSharp.MSBuild.ProjectManager
    65.         Failed to load project file 'f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-Editor.csproj'.
    66. f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-Editor.csproj
    67. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1179,5): Error: Die Verweisassemblys für Framework ".NETFramework,Version=v4.5" wurden nicht gefunden. Installieren Sie zum Beheben dieses Problems das SDK oder das Paket zur Festlegung von Zielversionen für die vorliegende Frameworkversion, oder legen Sie als neues Ziel für die Anwendung eine Version des Frameworks fest, für die Sie das SDK oder Paket zur Festlegung der Zielversionen installiert haben. Assemblys werden im globalen Assemblycache (GAC) aufgelöst und anstelle von Verweisassemblys verwendet. Daher wird die Assembly für das gewünschte Framework unter Umständen nicht ordnungsgemäß als Ziel festgelegt.
    68.  
    69. [fail]: OmniSharp.MSBuild.ProjectManager
    70.         Attemped to update project that is not loaded: f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-firstpass.csproj
    71. [fail]: OmniSharp.MSBuild.ProjectManager
    72.         Attemped to update project that is not loaded: f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-Editor-firstpass.csproj
    73. [fail]: OmniSharp.MSBuild.ProjectManager
    74.         Attemped to update project that is not loaded: f:\4 - Spiele\12 - Burg Falkenstein\Prototypen\BF_Prototyp_1\BF_Prototyp_1\Assembly-CSharp-Editor.csproj
    75.  
     
    MihaPro_CarX and ScaniX like this.
  2. Nit_Ram

    Nit_Ram

    Joined:
    May 8, 2016
    Posts:
    27
    Or do I have to install any further .NET frameworks? .NET-framework 4.5 doesn't exist, as it's not supported.
     
  3. ScaniX

    ScaniX

    Joined:
    Apr 10, 2016
    Posts:
    31
    I have the very same problem. Tried installing all kinds of .NETs, mono and other stuff. Nothing fixed it (yet).
    I changed the target version in the XMLs and set them all to readonly, so I can at least work again. Whenever you add new classes, you need to update them, though.
     
  4. nick_stage

    nick_stage

    Joined:
    Nov 9, 2017
    Posts:
    2
    Also having this problem as of the upgrade to 2018.3. Help!
     
    MihaPro_CarX likes this.
  5. MihaPro_CarX

    MihaPro_CarX

    Joined:
    Apr 5, 2017
    Posts:
    17
    If you have VS (not Code), need install .Net Framework 4.5 targeting package.

    upload_2019-1-10_11-27-28.png
     
  6. ScaniX

    ScaniX

    Joined:
    Apr 10, 2016
    Posts:
    31
    Not using Visual Studio, so this is not really an option as I do not want to download and install the whole Visual Studio for this. But your post made me give it another try and I finally fixed it. :D

    There really is no way to install 4.5 as windows is always telling you that you already have a newer version and the targeting pack does not exist (at least I could not find it) as separate download, but...

    https://developer.microsoft.com/en-us/windows/downloads/sdk-archive

    Here you can download the entry "Windows 8" (Some Windows SDK from 2012).
    In the setup disable everything but the .NET development entry and continue.
    Have fun!
     
    Last edited: Jan 10, 2019
    bitt3rman likes this.
  7. Nit_Ram

    Nit_Ram

    Joined:
    May 8, 2016
    Posts:
    27
    Scanix, you are my hero!
     
    bitt3rman likes this.
  8. ScaniX

    ScaniX

    Joined:
    Apr 10, 2016
    Posts:
    31
    Glad I could help. :)