Skip to content

Commit

Permalink
Add new project for building the Unity version of the library which c…
Browse files Browse the repository at this point in the history
…onsists of a single DLL and the Vector2Int class is renamed to EdgarVector2Int to pravent ambiguous references
  • Loading branch information
OndrejNepozitek committed Sep 8, 2020
1 parent 9b7e9d3 commit 2ced5ce
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
14 changes: 14 additions & 0 deletions EdgarDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Edgar.SandboxEvolutionRunne
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Edgar.Examples", "src\Edgar.Examples\Edgar.Examples.csproj", "{85887133-F036-4158-AD99-B9BBC4855728}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Edgar.UnityBuild", "src\Edgar.UnityBuild\Edgar.UnityBuild.csproj", "{C32F2964-B2D7-4FD7-A902-2478835C384D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -141,6 +143,18 @@ Global
{85887133-F036-4158-AD99-B9BBC4855728}.Release|x64.Build.0 = Release|Any CPU
{85887133-F036-4158-AD99-B9BBC4855728}.Release|x86.ActiveCfg = Release|Any CPU
{85887133-F036-4158-AD99-B9BBC4855728}.Release|x86.Build.0 = Release|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Debug|x64.ActiveCfg = Debug|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Debug|x64.Build.0 = Debug|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Debug|x86.ActiveCfg = Debug|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Debug|x86.Build.0 = Debug|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Release|Any CPU.Build.0 = Release|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Release|x64.ActiveCfg = Release|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Release|x64.Build.0 = Release|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Release|x86.ActiveCfg = Release|Any CPU
{C32F2964-B2D7-4FD7-A902-2478835C384D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
37 changes: 37 additions & 0 deletions src/Edgar.UnityBuild/Edgar.UnityBuild.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ILRepack.MSBuild.Task" Version="2.0.13" />
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Edgar\Edgar.csproj" />
</ItemGroup>

<Target Name="CustomAfterBuild" AfterTargets="Build">
<ItemGroup>
<CopyItems Include="$(SolutionDir)src\Edgar\bin\$(Configuration)\netstandard2.0\*.*" />
</ItemGroup>
<RemoveDir Directories="$(TargetDir)\Edgar" />
<Copy SourceFiles="@(CopyItems)" DestinationFolder="$(TargetDir)\Edgar" />

<PropertyGroup>
<WorkingDirectory>$(MSBuildThisFileDirectory)bin\$(Configuration)\$(TargetFramework)</WorkingDirectory>
</PropertyGroup>

<ILRepack
OutputType="$(OutputType)"
MainAssembly="$(WorkingDirectory)\Edgar\Edgar.dll"
OutputAssembly="$(WorkingDirectory)\EdgarSingleFile\EdgarSingleFile.dll"
InputAssemblies="$(WorkingDirectory)\Edgar\*.dll"
WilcardInputAssemblies="true"
WorkingDirectory="$(WorkingDirectory)" />
</Target>

</Project>
36 changes: 36 additions & 0 deletions src/Edgar.UnityBuild/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.IO;
using System.Linq;
using Mono.Cecil;

namespace Edgar.UnityBuild
{
class Program
{
static void Main(string[] args)
{
var assemblyName = "EdgarSingleFile.dll";
var sourceDir = "EdgarSingleFile";
var targetDir = "EdgarSingleFileModified";

Directory.Delete(targetDir, true);
Directory.CreateDirectory(targetDir);

CopyFilesRecursively(new DirectoryInfo(sourceDir), new DirectoryInfo(targetDir));

var moduleDefinition = ModuleDefinition.ReadModule(Path.Combine(sourceDir, assemblyName));
var vectorType = moduleDefinition.Types.Single(x => x.Name == "Vector2Int");
vectorType.Name = "EdgarVector2Int";

var stream = new FileStream(Path.Combine(targetDir, assemblyName), FileMode.Create);
moduleDefinition.Write(stream);
}

public static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target) {
foreach (DirectoryInfo dir in source.GetDirectories())
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
foreach (FileInfo file in source.GetFiles())
file.CopyTo(Path.Combine(target.FullName, file.Name));
}
}
}

0 comments on commit 2ced5ce

Please sign in to comment.