Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,68 @@ How it works:

3. **Project File Adjustment**: Finally, `UnityPackage` modifies the `.csproj` file to reflect the C# version specified in the `csc.rsp`. This alerts your IDE to the correct language version to use, ensuring it can provide you with all the relevant language features.

Platform Support:
--------
1. Editor OS support: Mac / Linux / Windows.
2. Target OS support: Mac / Windows / Linux / iOS / Android / WebGL.
3. IDE support: Rider / VSCode / Visual Studio.

Supported AssemblyDefinition locations:
--------
1. Project - everything that is located in `Assets/` folder of your project.
2. Embedded Packages - everything that is located in `Packages/` folder of your project.
3. Local Packages - everything that is located anywhere on your pc with specified path with `file:` prefix in manifest.

> [!WARNING]
> Patch will modify the Editor installation, so all the projects that are using it will be affected (default for unity C# version will be used for compilation, but from newer (patched) dotnet sdk)
>
> **DON'T** put `.asmdef` with its `csc.rsp` at the root of the project (`Assets/`).
> Unity in that case will apply the specified C# version to everything, that may cause compile errors (e.g. `field` keyword is used as a name in some third party library).
> Place it in any subfolder (usually Scripts, but doesn't matter, just not at the root)


> [!NOTE]
> OS support: Mac / Linux / Windows.
> You can backup your editor just in case, but should be fine.
>
> Patch will modify the Editor installation, so all the projects that are using it will be affected (default for unity C# version will be used for compilation, but from newer (patched) dotnet sdk)
>
> Tested on target platforms: Mac / Windows / Linux / iOS / Android / WebGL
>
> Tested in IDEs:
>
> `Rider 2025.1` with integration package `com.unity.ide.rider@3.0.36`
>
> `VSCode 1.99.3` with integration package `com.unity.ide.visualstudio@2.0.23`
>
> `Visual Studio Community 2022 17.13.6` with integration package `com.unity.ide.visualstudio@2.0.23`
> Opening the editor in `safe mode` will not apply the patch, so you may see a lot of errors in IDE only. It will be applied when you will exit the safe mode, so when all compile errors from editor console are fixed.

How to Install:
---------------

1. Add the package via git url ``https://github.com/kandreyc/unity-csharp-patch.git#v1.5.0``
1. Add the package via git url ``https://github.com/kandreyc/unity-csharp-patch.git#v1.6.0`` or download latest package from [releases](https://github.com/kandreyc/unity-csharp-patch/releases)
2. Ensure Unity Editor is closed.
3. Ensure latest dotnet sdk is installed. [Download Page](https://dotnet.microsoft.com/en-us/download)
4. Open terminal at folder ``EditorPatch~`` inside the added package.
5. Patch the editor (administrative privileges are required):

Mac / Linux:
```
$ dotnet UnityEditorPatch.dll apply --editor '/Applications/Unity/Hub/Editor/2022.3.21f1' --allow-prerelease
```
where ``--editor`` - path to the unity editor

where ``--allow-prerelease`` - (optional) allows to use prerelease dotnet sdk
Windows:
```
$ dotnet UnityEditorPatch.dll apply --editor "C:/Program Files/Unity/Hub/Editor/2022.3.21f1" --allow-prerelease
```
    where:
- ``--editor`` - path to the unity editor
- ``--allow-prerelease`` - (optional) allows to use prerelease dotnet sdk

In case if you want to revert the patch:

Mac / Linux:
```
$ dotnet UnityEditorPatch.dll revert --editor '/Applications/Unity/Hub/Editor/2022.3.21f1'
```
where ``--editor`` - path to the unity editor
Windows:
```
$ dotnet UnityEditorPatch.dll revert --editor "C:/Program Files/Unity/Hub/Editor/2022.3.21f1"
```

    where:
- ``--editor`` - path to the unity editor

6. Open the Unity Editor with your project and create a `csc.rsp` file alongside desired `.asmdef` with the following content:
```
-langVersion:13
-langVersion:14
-nullable:enable
```
where:

    where:
- ``langVersion`` (optional) - C# version you want to be used for this ``.asmdef``. Values are ``10``, ``11``, ``12``, ``13``, ``14``
- ``nullable`` (optional) - allows to use nullables like ``string?`` without defining ``#nullable enable/disable`` in each file where it used. Values are ``enable``, ``disable``

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ private static void OnPostprocessAllAssets(string[] imported, string[] deleted,
AssetDatabase.Refresh();
}

[InitializeOnLoadMethod]
public static void TriggerRefreshOnSafeModeExit()
{
const string isPatched = "__is_csproj_patched";

if (!SessionState.GetBool(isPatched, false))
{
SessionState.SetBool(isPatched, true);
SolutionUtility.RegenerateProjects();
}
}

private static bool IsCsc(string asset)
{
return Path.GetFileName(asset) is "csc.rsp";
Expand Down
2 changes: 1 addition & 1 deletion UnityCSharpPatch/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"com.test.local-outer-package": "file:../AnotherPackages/com.test.local-outer-package",
"com.unity.feature.development": "1.0.1",
"com.unity.ide.rider": "3.0.34",
"com.unity.ide.rider": "3.0.36",
"com.unity.ugui": "1.0.0",
"com.unity.modules.androidjni": "1.0.0"
}
Expand Down
10 changes: 5 additions & 5 deletions UnityCSharpPatch/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
"source": "builtin",
"dependencies": {
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.ide.rider": "3.0.31",
"com.unity.ide.rider": "3.0.36",
"com.unity.ide.vscode": "1.2.5",
"com.unity.editorcoroutines": "1.0.0",
"com.unity.performance.profile-analyzer": "1.2.2",
"com.unity.performance.profile-analyzer": "1.2.3",
"com.unity.test-framework": "1.1.33",
"com.unity.testtools.codecoverage": "1.2.6"
}
},
"com.unity.ide.rider": {
"version": "3.0.34",
"version": "3.0.36",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -72,14 +72,14 @@
"url": "https://packages.unity.com"
},
"com.unity.performance.profile-analyzer": {
"version": "1.2.2",
"version": "1.2.3",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.settings-manager": {
"version": "2.0.1",
"version": "2.1.0",
"depth": 2,
"source": "registry",
"dependencies": {},
Expand Down
4 changes: 2 additions & 2 deletions UnityCSharpPatch/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2022.3.50f1
m_EditorVersionWithRevision: 2022.3.50f1 (c3db7f8bf9b1)
m_EditorVersion: 2022.3.62f2
m_EditorVersionWithRevision: 2022.3.62f2 (7670c08855a9)
2 changes: 1 addition & 1 deletion UnityEditorPatch/UnityEditorPatch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<DebugType>None</DebugType>
<DebugSymbols>false</DebugSymbols>
Expand Down