Skip to content

Commit 40ebba4

Browse files
committed
Add HotReload.
Update usings.
1 parent 796288b commit 40ebba4

File tree

10 files changed

+135
-15
lines changed

10 files changed

+135
-15
lines changed

Entrypoint.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public static void Start()
1010
#endif
1111
Harmony = new(nameof(Doorstop));
1212
Harmony.PatchAll();
13+
HotReloader.Initialize();
1314
}
1415
}

GlobalUsings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
global using HotReload;
2+
global using System;
3+
global using System.Security.Policy;

Patches.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Security.Policy;
3-
4-
namespace Doorstop;
1+
namespace Doorstop;
52

63
[Harmony]
74
public static partial class Patches

Shared.props.csproj

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<LangVersion>preview</LangVersion>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Publicize Include="mscorlib" />
9+
<PackageReference Include="Krafs.Publicizer" Version="1.*">
10+
<PrivateAssets>all</PrivateAssets>
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12+
</PackageReference>
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="Mono.HotReload" Version="*" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<Using Include="HarmonyLib" />
25+
</ItemGroup>
26+
27+
</Project>

Tests/HotReloadTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.IO;
3+
using System.Reflection;
4+
using HotReload;
5+
6+
namespace Tests
7+
{
8+
public static class Tests
9+
{
10+
public static void Main()
11+
{
12+
Doorstop.Entrypoint.Start();
13+
Console.ReadKey();
14+
15+
var dir = Environment.CurrentDirectory;
16+
HotReloader.AddSearchDirectory(dir);
17+
18+
var original = Assembly.GetExecutingAssembly();
19+
FileInfo file = new("Test.dll");
20+
HotReloader.HandleLoad(original, codeBase: file);
21+
22+
MyMethod();
23+
HotReloader.Load(file);
24+
MyMethod();
25+
}
26+
[HotReloadable]
27+
public static void MyMethod()
28+
{
29+
Console.WriteLine("A");
30+
}
31+
}
32+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"profiles": {
3+
"Run Mono": {
4+
"commandName": "Executable",
5+
"executablePath": "C:\\Program Files\\Mono\\bin\\mono.exe",
6+
"commandLineArgs": "--debug Tests.exe"
7+
}
8+
}
9+
}

Tests/Test.dll

5.5 KB
Binary file not shown.

Tests/Tests.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net48</TargetFramework>
6+
<LangVersion>preview</LangVersion>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\UnityDebug.csproj" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Test.dll" CopyToOutputDirectory="Always" />
15+
</ItemGroup>
16+
17+
<Import Project="$(SolutionDir)Shared.props.csproj" />
18+
19+
</Project>

UnityDebug.csproj

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,21 @@
2424
<Compile Remove="$(BaseOutputPath)**" />
2525
<EmbeddedResource Remove="$(BaseOutputPath)**" />
2626
<None Remove="$(BaseOutputPath)**" />
27+
<!-- Hide inner projects -->
28+
<Compile Remove="HotReload\**" />
29+
<EmbeddedResource Remove="HotReload\**" />
30+
<None Remove="HotReload\**" />
31+
<Compile Remove="Tests\**" />
32+
<EmbeddedResource Remove="Tests\**" />
33+
<None Remove="Tests\**" />
2734
</ItemGroup>
2835

29-
<ItemGroup>
30-
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
31-
</ItemGroup>
32-
33-
<ItemGroup>
34-
<Reference Include="Mono.Cecil" HintPath="libs\Mono.Cecil.dll" />
35-
<Reference Include="Mono.CompilerServices.SymbolWriter" HintPath="libs\Mono.CompilerServices.SymbolWriter.dll" />
36-
<Reference Include="pdb2mdb" HintPath="libs\pdb2mdb.exe" />
37-
</ItemGroup>
36+
<Import Project="$(SolutionDir)Shared.props.csproj" />
3837

3938
<ItemGroup>
40-
<Using Include="HarmonyLib" />
39+
<Reference Include="Mono.Cecil" HintPath="libs\Mono.Cecil.dll" />
40+
<Reference Include="Mono.CompilerServices.SymbolWriter" HintPath="libs\Mono.CompilerServices.SymbolWriter.dll" />
41+
<Reference Include="pdb2mdb" HintPath="libs\pdb2mdb.exe" />
4142
</ItemGroup>
4243

4344
<Target Name="cleanup" AfterTargets="BeforeClean">

UnityDebug.sln

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.4.33027.239
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityDebug", "UnityDebug.csproj", "{B23E25E0-997B-4922-B258-7AF385C77529}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnityDebug", "UnityDebug.csproj", "{B23E25E0-997B-4922-B258-7AF385C77529}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AA2923C3-FB56-4987-AF8A-F286B7B30E42}"
9+
ProjectSection(SolutionItems) = preProject
10+
Shared.props.csproj = Shared.props.csproj
11+
EndProjectSection
12+
EndProject
13+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}"
714
EndProject
815
Global
916
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -45,6 +52,30 @@ Global
4552
{B23E25E0-997B-4922-B258-7AF385C77529}.Win|x64.Build.0 = Win|x64
4653
{B23E25E0-997B-4922-B258-7AF385C77529}.Win|x86.ActiveCfg = Win|x86
4754
{B23E25E0-997B-4922-B258-7AF385C77529}.Win|x86.Build.0 = Win|x86
55+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
57+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Debug|x64.ActiveCfg = Debug|Any CPU
58+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Debug|x64.Build.0 = Debug|Any CPU
59+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Debug|x86.ActiveCfg = Debug|Any CPU
60+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Debug|x86.Build.0 = Debug|Any CPU
61+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Linux|Any CPU.ActiveCfg = Debug|Any CPU
62+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Linux|Any CPU.Build.0 = Debug|Any CPU
63+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Linux|x64.ActiveCfg = Debug|Any CPU
64+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Linux|x64.Build.0 = Debug|Any CPU
65+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Linux|x86.ActiveCfg = Debug|Any CPU
66+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Linux|x86.Build.0 = Debug|Any CPU
67+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.MacOS|Any CPU.ActiveCfg = Debug|Any CPU
68+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.MacOS|Any CPU.Build.0 = Debug|Any CPU
69+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.MacOS|x64.ActiveCfg = Debug|Any CPU
70+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.MacOS|x64.Build.0 = Debug|Any CPU
71+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.MacOS|x86.ActiveCfg = Debug|Any CPU
72+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.MacOS|x86.Build.0 = Debug|Any CPU
73+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Win|Any CPU.ActiveCfg = Debug|Any CPU
74+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Win|Any CPU.Build.0 = Debug|Any CPU
75+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Win|x64.ActiveCfg = Debug|Any CPU
76+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Win|x64.Build.0 = Debug|Any CPU
77+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Win|x86.ActiveCfg = Debug|Any CPU
78+
{2CBFDEB6-487E-45EB-9F6F-86D0614601B5}.Win|x86.Build.0 = Debug|Any CPU
4879
EndGlobalSection
4980
GlobalSection(SolutionProperties) = preSolution
5081
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)