Skip to content

Commit 5a1e296

Browse files
authored
Fix compiler error on 2023.1 .net framework (#594)
* fix not compiling on 2023.1 with editor assembly compatibility level set to .net framework * update to 4.0.1
1 parent d25483b commit 5a1e296

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/NuGetForUnity/Editor/Configuration/ConfigurationEncryptionHelper.cs

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER) || NUGETFORUNITY_CLI)
1+
#pragma warning disable SA1512,SA1124 // Single-line comments should not be followed by blank line
2+
#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER && NET_STANDARD) || NUGETFORUNITY_CLI)
23
using JetBrains.Annotations;
34
#else
45
using System.Security.Cryptography;
56
#endif
7+
8+
#region No ReShaper
9+
10+
// ReSharper disable All
11+
// needed because 'JetBrains.Annotations.NotNull' and 'System.Diagnostics.CodeAnalysis.NotNull' collide if this file is compiled with a never version of Unity / C#
12+
using SuppressMessageAttribute = System.Diagnostics.CodeAnalysis.SuppressMessageAttribute;
13+
14+
// ReSharper restore All
15+
16+
#endregion
17+
618
using System;
7-
using System.Diagnostics.CodeAnalysis;
819
using System.Text;
920
using UnityEngine;
1021

1122
namespace NugetForUnity.Configuration
1223
{
1324
/// <summary>
14-
/// Helper to encrypt sensitive data so they don't need to be stored in plaintext inside the configuration file.
25+
/// Helper to encrypt sensitive data so they don't need to be stored in plain-text inside the configuration file.
1526
/// </summary>
1627
internal static class ConfigurationEncryptionHelper
1728
{
1829
private static readonly byte[] EntropyBytes = Encoding.UTF8.GetBytes("NuGet");
1930

20-
#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER) || NUGETFORUNITY_CLI)
31+
#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER && NET_STANDARD) || NUGETFORUNITY_CLI)
2132

2233
// on .net framework the type lives in 'System.Security' on .net standard it in 'System.Security.Cryptography.ProtectedData'
2334
[ItemCanBeNull]
@@ -44,7 +55,7 @@ public static string EncryptString(string value)
4455
{
4556
var decryptedByteArray = Encoding.UTF8.GetBytes(value);
4657

47-
#if (UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER) || NUGETFORUNITY_CLI
58+
#if (UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER && NET_STANDARD) || NUGETFORUNITY_CLI
4859
#pragma warning disable CA1416 // Validate platform compatibility
4960
var encryptedByteArray = ProtectedData.Protect(decryptedByteArray, EntropyBytes, DataProtectionScope.CurrentUser);
5061
#pragma warning restore CA1416 // Validate platform compatibility
@@ -86,7 +97,7 @@ public static string DecryptString(string encryptedString)
8697
{
8798
var encryptedByteArray = Convert.FromBase64String(encryptedString);
8899

89-
#if (UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER) || NUGETFORUNITY_CLI
100+
#if (UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER && NET_STANDARD) || NUGETFORUNITY_CLI
90101
#pragma warning disable CA1416 // Validate platform compatibility
91102
var decryptedByteArray = ProtectedData.Unprotect(encryptedByteArray, EntropyBytes, DataProtectionScope.CurrentUser);
92103
#pragma warning restore CA1416 // Validate platform compatibility
@@ -110,7 +121,7 @@ public static string DecryptString(string encryptedString)
110121
}
111122
}
112123

113-
#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER) || NUGETFORUNITY_CLI)
124+
#if !((UNITY_EDITOR_WIN && UNITY_2023_1_OR_NEWER && NET_STANDARD) || NUGETFORUNITY_CLI)
114125
[CanBeNull]
115126
private static byte[] ProtectOrUnprotectUsingReflection(string methodName, byte[] data)
116127
{

src/NuGetForUnity/Editor/Ui/NugetPreferences.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class NugetPreferences : SettingsProvider
2828
/// <summary>
2929
/// The current version of NuGet for Unity.
3030
/// </summary>
31-
public const string NuGetForUnityVersion = "4.0.0";
31+
public const string NuGetForUnityVersion = "4.0.1";
3232

3333
/// <summary>
3434
/// The current position of the scroll bar in the GUI.

src/NuGetForUnity/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.github-glitchenzo.nugetforunity",
33
"displayName": "NuGetForUnity",
4-
"version": "4.0.0",
4+
"version": "4.0.1",
55
"description": "A NuGet Package Manager for Unity",
66
"unity": "2018.4",
77
"keywords": [

0 commit comments

Comments
 (0)