Skip to content

Commit

Permalink
Fixed path not found exception when EB loading on .net9.0 SDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Dec 9, 2024
1 parent d8da7d3 commit 197153e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 51 deletions.
4 changes: 2 additions & 2 deletions src/Epoxy.Build/Epoxy.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>

<PropertyGroup Condition="('$(TargetFramework)' == 'netcoreapp3.1') OR ('$(TargetFramework)' == 'net5.0') OR ('$(TargetFramework)' == 'net6.0') OR ('$(TargetFramework)' == 'net7.0') OR ('$(TargetFramework)' == 'net8.0')">
<RollForward>Minor</RollForward>
<PropertyGroup Condition="('$(TargetFramework)' == 'netcoreapp3.1') OR ('$(TargetFramework)' == 'net5.0') OR ('$(TargetFramework)' == 'net6.0') OR ('$(TargetFramework)' == 'net7.0') OR ('$(TargetFramework)' == 'net8.0') OR ('$(TargetFramework)' == 'net9.0')">
<RollForward>LatestMajor</RollForward>
</PropertyGroup>

<ItemGroup>
Expand Down
77 changes: 77 additions & 0 deletions src/Epoxy.Build/build/Epoxy.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,81 @@
<_EB_ScriptBaseDir>$(MSBuildThisFileDirectory)</_EB_ScriptBaseDir>
</PropertyGroup>

<!-- ======================== -->
<!-- Custom task -->

<!-- https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-roslyncodetaskfactory?view=vs-2022#provide-backward-compatibility -->
<Choose>
<When Condition="'$(MSBuildVersion.Substring(0,2))' &gt;= 16 OR ('$(MSBuildVersion.Substring(0,2))' == 15 AND '$(MSBuildVersion.Substring(3,1))' &gt;= 8)">
<PropertyGroup>
<_EB_TaskFactory>RoslynCodeTaskFactory</_EB_TaskFactory>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<_EB_TaskFactory>CodeTaskFactory</_EB_TaskFactory>
</PropertyGroup>
</Otherwise>
</Choose>

<UsingTask
TaskName="_EB_GetCombinedReferencesBasePath"
TaskFactory="$(_EB_TaskFactory)"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<References ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<CombinedReferencesBasePath Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<!-- HACK: Will cause compilation error by using `System.Collection.Generic` and/or `System.Linq` on MacOS
(Maybe related both mono environment and unreferenced core assembly on `RoslynCodeTaskFactory`) -->
<Using Namespace="System.Collections"/>
<Using Namespace="Microsoft.Build.Framework"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
var candidates = new Hashtable();
foreach (var item in References)
{
if (!string.IsNullOrEmpty(item.ItemSpec))
{
var path = Path.GetDirectoryName(Path.GetFullPath(item.ItemSpec));
candidates[path] = path;
}
}
var pathList = new object[candidates.Keys.Count];
candidates.Keys.CopyTo(pathList, 0);
CombinedReferencesBasePath = string.Join(";", pathList);
]]>
</Code>
</Task>
</UsingTask>

<UsingTask
TaskName="_EB_CandidateToolingDir"
TaskFactory="$(_EB_TaskFactory)"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<ToolingDir ParameterType="Microsoft.Build.Framework.ITaskItem" Required="true" />
<CandidateDir Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Using Namespace="Microsoft.Build.Framework"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
string path = Path.GetFullPath(ToolingDir.ItemSpec);
if (!Directory.Exists(path))
{
string basePath = Path.GetDirectoryName(path);
path = Path.Combine(basePath, "net9.0");
}
CandidateDir = path;
]]>
</Code>
</Task>
</UsingTask>

</Project>
65 changes: 16 additions & 49 deletions src/Epoxy.Build/build/Epoxy.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -50,65 +50,32 @@
</PropertyGroup>

<PropertyGroup>
<_EB_ToolingDir>$([System.IO.Path]::Combine('$(_EB_ScriptBaseDir)','..','tools','$(_EB_PlatformName)'))</_EB_ToolingDir>
<_EB_ToolingBaseDir>$([System.IO.Path]::Combine('$(_EB_ScriptBaseDir)','..','tools','$(_EB_PlatformName)'))</_EB_ToolingBaseDir>
</PropertyGroup>

<!-- ======================== -->
<!-- Custom task -->

<UsingTask
TaskName="GetCombinedReferencesBasePath"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<References ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<CombinedReferencesBasePath Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<!-- HACK: Will cause compilation error by using `System.Collection.Generic` and/or `System.Linq` on MacOS
(Maybe related both mono environment and unreferenced core assembly on `RoslynCodeTaskFactory`) -->
<Using Namespace="System.Collections"/>
<Using Namespace="Microsoft.Build.Framework"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
var candidates = new Hashtable();
foreach (var item in References)
{
if (!string.IsNullOrEmpty(item.ItemSpec))
{
var path = Path.GetDirectoryName(Path.GetFullPath(item.ItemSpec));
candidates[path] = path;
}
}
var pathList = new object[candidates.Keys.Count];
candidates.Keys.CopyTo(pathList, 0);
CombinedReferencesBasePath = string.Join(";", pathList);
]]>
</Code>
</Task>
</UsingTask>

<!-- ======================== -->
<!-- Build target -->

<Target Name="EpoxyBuild" AfterTargets="AfterCompile"
Condition="'$(EpoxyBuildEnable)' == 'True'">


<_EB_CandidateToolingDir ToolingDir="$(_EB_ToolingBaseDir)">
<Output TaskParameter="CandidateDir" PropertyName="_EB_ToolingCandidateDir" />
</_EB_CandidateToolingDir>

<PropertyGroup>
<EpoxyBuildToolingRuntimeName Condition="'$(EpoxyBuildToolingRuntimeName)' == ''">$(_EB_RuntimeName)</EpoxyBuildToolingRuntimeName>
<EpoxyBuildToolingDir Condition="'$(EpoxyBuildToolingDir)' == ''">$([System.IO.Path]::GetFullPath('$(_EB_ToolingDir)'))</EpoxyBuildToolingDir>
<EpoxyBuildToolingPath Condition="'$(EpoxyBuildToolingPath)' == ''">$([System.IO.Path]::Combine('$(EpoxyBuildToolingDir)','$(_EB_ExecutableName)'))</EpoxyBuildToolingPath>
<EpoxyBuildToolingTraceOption Condition="$(EpoxyBuildTrace)"> -t</EpoxyBuildToolingTraceOption>
<EpoxyBuildToolingDebugOption Condition="$(EpoxyBuildDebug)"> -d</EpoxyBuildToolingDebugOption>
<_EB_ToolingRuntimeName Condition="'$(_EB_ToolingRuntimeName)' == ''">$(_EB_RuntimeName)</_EB_ToolingRuntimeName>
<_EB_ToolingDir Condition="'$(_EB_ToolingDir)' == ''">$(_EB_ToolingCandidateDir)</_EB_ToolingDir>
<_EB_ToolingPath Condition="'$(_EB_ToolingPath)' == ''">$([System.IO.Path]::Combine('$(_EB_ToolingDir)','$(_EB_ExecutableName)'))</_EB_ToolingPath>
<_EB_ToolingTraceOption Condition="'$(EpoxyBuildTrace)' == 'True'"> -t</_EB_ToolingTraceOption>
<_EB_ToolingDebugOption Condition="'$(EpoxyBuildDebug)' == 'True'"> -d</_EB_ToolingDebugOption>
</PropertyGroup>

<GetCombinedReferencesBasePath References="@(ReferencePath)">
<Output TaskParameter="CombinedReferencesBasePath" PropertyName="CombinedReferencesBasePath" />
</GetCombinedReferencesBasePath>
<_EB_GetCombinedReferencesBasePath References="@(ReferencePath)">
<Output TaskParameter="CombinedReferencesBasePath" PropertyName="_EB_CombinedReferencesBasePath" />
</_EB_GetCombinedReferencesBasePath>

<Exec WorkingDirectory="$(EpoxyBuildToolingDir)"
Command="$(EpoxyBuildToolingRuntimeName)&quot;$(EpoxyBuildToolingPath)&quot;$(EpoxyBuildToolingTraceOption)$(EpoxyBuildToolingDebugOption) &quot;$(CombinedReferencesBasePath)&quot; &quot;$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)&quot;" />
<Exec WorkingDirectory="$(_EB_ToolingDir)"
Command="$(_EB_ToolingRuntimeName)&quot;$(_EB_ToolingPath)&quot;$(_EB_ToolingTraceOption)$(_EB_ToolingDebugOption) &quot;$(_EB_CombinedReferencesBasePath)&quot; &quot;$(ProjectDir)$(IntermediateOutputPath)$(TargetFileName)&quot;" />
</Target>
</Project>

0 comments on commit 197153e

Please sign in to comment.