<Project>
<UsingTask TaskName="WriteNativeSupportManifests" TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)/Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<PlatformSource ParameterType="System.String" Required="true" />
<Modules ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.IO" />
<Using Namespace="System.Text" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs"><![CDATA[
var source = File.ReadAllText(PlatformSource);
var version = Regex.Match(source, "const string PluginVersion = \"([0-9A-Za-z.+-]+)\";");
var game = Regex.Match(source, "const string GameHash = \"([a-f0-9]{64})\";");
if (!version.Success || !game.Success)
{
Log.LogError("Native support version or verified game identity is missing from Platform.cs.");
return false;
}
foreach (var module in Modules)
{
var hash = module.GetMetadata("FileHash").ToLowerInvariant();
if (!Regex.IsMatch(hash, "^[a-f0-9]{64}$"))
{
Log.LogError("Native support binary has no SHA-256: " + module.ItemSpec);
return false;
}
var loader = module.GetMetadata("Kind") == "Loader";
var text = loader
? "{\n \"id\": \"XFEEDToolBox.Plugin\",\n \"version\": \"" + version.Groups[1].Value + "\",\n \"loader\": \"dinput8.dll\",\n \"sha256\": \"" + hash + "\",\n \"supportedGameSha256\": \"" + game.Groups[1].Value + "\",\n \"supportsTrade\": false,\n \"supportsRelog\": true,\n \"supportsNavigation\": true\n}\n"
: "{\n \"schema\": 1,\n \"name\": \"XFEEDToolBox.Interaction\",\n \"file\": \"XFEEDInteraction.dll\",\n \"sha256\": \"" + hash + "\",\n \"gameSha256\": \"" + game.Groups[1].Value + "\"\n}\n";
var path = module.GetMetadata("ManifestPath");
if (!File.Exists(path) || File.ReadAllText(path) != text)
File.WriteAllText(path, text, new UTF8Encoding(false));
}
]]></Code>
</Task>
</UsingTask>
<!-- Project references restore and build the source graph. Publish is needed
here because NativeAOT produces its native DLL at publish time. -->
<Target Name="BuildEmbeddedNativeSupport" BeforeTargets="AssignTargetPaths"
DependsOnTargets="ResolveProjectReferences"
Condition="'$(DesignTimeBuild)' != 'true'">
<PropertyGroup>
<_NativeSupportDirectory>$([System.IO.Path]::GetFullPath('$(IntermediateOutputPath)native-support/'))</_NativeSupportDirectory>
</PropertyGroup>
<ItemGroup>
<_NativeSupportProject Include="$(MSBuildThisFileDirectory)../Loader/Loader.csproj">
<Kind>Loader</Kind><Binary>dinput8.dll</Binary><ResourcePath>dinput8.dll</ResourcePath>
<Manifest>package.json</Manifest><ManifestResourcePath>package.json</ManifestResourcePath>
</_NativeSupportProject>
<_NativeSupportProject Include="$(MSBuildThisFileDirectory)../Interaction/Interaction.csproj">
<Kind>Interaction</Kind><Binary>XFEEDInteraction.dll</Binary><ResourcePath>XFEEDInteraction.dll</ResourcePath>
<Manifest>interaction.json</Manifest><ManifestResourcePath>interaction.json</ManifestResourcePath>
</_NativeSupportProject>
<_NativeSupportProject Include="$(MSBuildThisFileDirectory)../SessionRecovery/SessionRecovery.csproj">
<Kind>DockingControl</Kind><Binary>XFEEDInteraction.dll</Binary><ResourcePath>DockingControl/XFEEDInteraction.dll</ResourcePath>
<Manifest>interaction.json</Manifest><ManifestResourcePath>DockingControl/interaction.json</ManifestResourcePath>
</_NativeSupportProject>
<_NativeSupportProject Include="$(MSBuildThisFileDirectory)../CruiseControl/CruiseControl.csproj">
<Kind>CruiseControl</Kind><Binary>XFEEDInteraction.dll</Binary><ResourcePath>CruiseControl/XFEEDInteraction.dll</ResourcePath>
<Manifest>interaction.json</Manifest><ManifestResourcePath>CruiseControl/interaction.json</ManifestResourcePath>
</_NativeSupportProject>
</ItemGroup>
<MSBuild Projects="@(_NativeSupportProject)" Targets="Publish" BuildInParallel="false"
RemoveProperties="TargetFramework;PublishSingleFile;IsPublishable"
Properties="Configuration=$(Configuration);Platform=x64;RuntimeIdentifier=win-x64;SelfContained=true;PublishDir=$(_NativeSupportDirectory)%(_NativeSupportProject.Kind)/" />
<ItemGroup>
<_NativeSupportBinary Include="@(_NativeSupportProject->'$(_NativeSupportDirectory)%(Kind)/%(Binary)')">
<Kind>%(_NativeSupportProject.Kind)</Kind>
<ResourcePath>%(_NativeSupportProject.ResourcePath)</ResourcePath>
<ManifestPath>$(_NativeSupportDirectory)%(_NativeSupportProject.Kind)/%(_NativeSupportProject.Manifest)</ManifestPath>
<ManifestResourcePath>%(_NativeSupportProject.ManifestResourcePath)</ManifestResourcePath>
</_NativeSupportBinary>
</ItemGroup>
<GetFileHash Files="@(_NativeSupportBinary)" Algorithm="SHA256">
<Output TaskParameter="Items" ItemName="_HashedNativeSupportBinary" />
</GetFileHash>
<WriteNativeSupportManifests PlatformSource="$(MSBuildThisFileDirectory)../Platform.cs" Modules="@(_HashedNativeSupportBinary)" />
<ItemGroup>
<EmbeddedResource Include="@(_HashedNativeSupportBinary)">
<LogicalName>XFEEDToolBox.NativeSupport.%(_HashedNativeSupportBinary.ResourcePath)</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="@(_HashedNativeSupportBinary->'%(ManifestPath)')">
<LogicalName>XFEEDToolBox.NativeSupport.%(_HashedNativeSupportBinary.ManifestResourcePath)</LogicalName>
</EmbeddedResource>
<FileWrites Include="@(_HashedNativeSupportBinary);@(_HashedNativeSupportBinary->'%(ManifestPath)')" />
</ItemGroup>
</Target>
</Project>
<Project>
<UsingTask TaskName="WriteNativeSupportManifests" TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)/Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<PlatformSource ParameterType="System.String" Required="true" />
<Modules ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.IO" />
<Using Namespace="System.Text" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs"><![CDATA[
var source = File.ReadAllText(PlatformSource);
var version = Regex.Match(source, "const string PluginVersion = \"([0-9A-Za-z.+-]+)\";");
var game = Regex.Match(source, "const string GameHash = \"([a-f0-9]{64})\";");
if (!version.Success || !game.Success)
{
Log.LogError("Native support version or verified game identity is missing from Platform.cs.");
return false;
}
foreach (var module in Modules)
{
var hash = module.GetMetadata("FileHash").ToLowerInvariant();
if (!Regex.IsMatch(hash, "^[a-f0-9]{64}$"))
{
Log.LogError("Native support binary has no SHA-256: " + module.ItemSpec);
return false;
}
var loader = module.GetMetadata("Kind") == "Loader";
var text = loader
? "{\n \"id\": \"XFEEDToolBox.Plugin\",\n \"version\": \"" + version.Groups[1].Value + "\",\n \"loader\": \"dinput8.dll\",\n \"sha256\": \"" + hash + "\",\n \"supportedGameSha256\": \"" + game.Groups[1].Value + "\",\n \"supportsTrade\": false,\n \"supportsRelog\": true,\n \"supportsNavigation\": true\n}\n"
: "{\n \"schema\": 1,\n \"name\": \"XFEEDToolBox.Interaction\",\n \"file\": \"XFEEDInteraction.dll\",\n \"sha256\": \"" + hash + "\",\n \"gameSha256\": \"" + game.Groups[1].Value + "\"\n}\n";
var path = module.GetMetadata("ManifestPath");
if (!File.Exists(path) || File.ReadAllText(path) != text)
File.WriteAllText(path, text, new UTF8Encoding(false));
}
]]></Code>
</Task>
</UsingTask>
<!-- Project references restore and build the source graph. Publish is needed
here because NativeAOT produces its native DLL at publish time. -->
<Target Name="BuildEmbeddedNativeSupport" BeforeTargets="AssignTargetPaths"
DependsOnTargets="ResolveProjectReferences"
Condition="'$(DesignTimeBuild)' != 'true'">
<PropertyGroup>
<_NativeSupportDirectory>$([System.IO.Path]::GetFullPath('$(IntermediateOutputPath)native-support/'))</_NativeSupportDirectory>
</PropertyGroup>
<ItemGroup>
<_NativeSupportProject Include="$(MSBuildThisFileDirectory)../Loader/Loader.csproj">
<Kind>Loader</Kind><Binary>dinput8.dll</Binary><ResourcePath>dinput8.dll</ResourcePath>
<Manifest>package.json</Manifest><ManifestResourcePath>package.json</ManifestResourcePath>
</_NativeSupportProject>
<_NativeSupportProject Include="$(MSBuildThisFileDirectory)../Interaction/Interaction.csproj">
<Kind>Interaction</Kind><Binary>XFEEDInteraction.dll</Binary><ResourcePath>XFEEDInteraction.dll</ResourcePath>
<Manifest>interaction.json</Manifest><ManifestResourcePath>interaction.json</ManifestResourcePath>
</_NativeSupportProject>
<_NativeSupportProject Include="$(MSBuildThisFileDirectory)../SessionRecovery/SessionRecovery.csproj">
<Kind>DockingControl</Kind><Binary>XFEEDInteraction.dll</Binary><ResourcePath>DockingControl/XFEEDInteraction.dll</ResourcePath>
<Manifest>interaction.json</Manifest><ManifestResourcePath>DockingControl/interaction.json</ManifestResourcePath>
</_NativeSupportProject>
<_NativeSupportProject Include="$(MSBuildThisFileDirectory)../CruiseControl/CruiseControl.csproj">
<Kind>CruiseControl</Kind><Binary>XFEEDInteraction.dll</Binary><ResourcePath>CruiseControl/XFEEDInteraction.dll</ResourcePath>
<Manifest>interaction.json</Manifest><ManifestResourcePath>CruiseControl/interaction.json</ManifestResourcePath>
</_NativeSupportProject>
</ItemGroup>
<MSBuild Projects="@(_NativeSupportProject)" Targets="Publish" BuildInParallel="false"
RemoveProperties="TargetFramework;PublishSingleFile;IsPublishable"
Properties="Configuration=$(Configuration);Platform=x64;RuntimeIdentifier=win-x64;SelfContained=true;PublishDir=$(_NativeSupportDirectory)%(_NativeSupportProject.Kind)/" />
<ItemGroup>
<_NativeSupportBinary Include="@(_NativeSupportProject->'$(_NativeSupportDirectory)%(Kind)/%(Binary)')">
<Kind>%(_NativeSupportProject.Kind)</Kind>
<ResourcePath>%(_NativeSupportProject.ResourcePath)</ResourcePath>
<ManifestPath>$(_NativeSupportDirectory)%(_NativeSupportProject.Kind)/%(_NativeSupportProject.Manifest)</ManifestPath>
<ManifestResourcePath>%(_NativeSupportProject.ManifestResourcePath)</ManifestResourcePath>
</_NativeSupportBinary>
</ItemGroup>
<GetFileHash Files="@(_NativeSupportBinary)" Algorithm="SHA256">
<Output TaskParameter="Items" ItemName="_HashedNativeSupportBinary" />
</GetFileHash>
<WriteNativeSupportManifests PlatformSource="$(MSBuildThisFileDirectory)../Platform.cs" Modules="@(_HashedNativeSupportBinary)" />
<ItemGroup>
<EmbeddedResource Include="@(_HashedNativeSupportBinary)">
<LogicalName>XFEEDToolBox.NativeSupport.%(_HashedNativeSupportBinary.ResourcePath)</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="@(_HashedNativeSupportBinary->'%(ManifestPath)')">
<LogicalName>XFEEDToolBox.NativeSupport.%(_HashedNativeSupportBinary.ManifestResourcePath)</LogicalName>
</EmbeddedResource>
<FileWrites Include="@(_HashedNativeSupportBinary);@(_HashedNativeSupportBinary->'%(ManifestPath)')" />
</ItemGroup>
</Target>
</Project>