mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-21 22:45:20 +00:00
Add ElectronNET.Build project (dll with custom MSBuild tasks)
This commit is contained in:
35
src/ElectronNET.Build/ElectronNET.Build.csproj
Normal file
35
src/ElectronNET.Build/ElectronNET.Build.csproj
Normal file
@@ -0,0 +1,35 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.3.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
<_DllTargetPath>$(MSBuildThisFileDirectory)\..\ElectronNET\build</_DllTargetPath>
|
||||
|
||||
</PropertyGroup>
|
||||
|
||||
<Target BeforeTargets="AfterBuild" Name="CopyToBuildFolder">
|
||||
|
||||
<ItemGroup>
|
||||
<OutputFiles Include="$(OutDir)**\*.dll"></OutputFiles>
|
||||
</ItemGroup>
|
||||
|
||||
<Message Text="Copy ElectronNET.Build.dll to destination: $(_DllTargetPath)" Importance="high"/>
|
||||
|
||||
<Copy SourceFiles="@(OutputFiles)"
|
||||
DestinationFolder="$(_DllTargetPath)\%(RecursiveDir)"
|
||||
OverwriteReadOnlyFiles="true"></Copy>
|
||||
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,2 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>
|
||||
39
src/ElectronNET.Build/PrintItemMetadata.cs
Normal file
39
src/ElectronNET.Build/PrintItemMetadata.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace ElectronNET.Build
|
||||
{
|
||||
using System;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
||||
public class DumpItemMetadataTask : Task
|
||||
{
|
||||
// The item group whose metadata will be dumped.
|
||||
[Required]
|
||||
public ITaskItem[] Items { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var item in this.Items)
|
||||
{
|
||||
// Log the item's identity (the Include attribute)
|
||||
this.Log.LogMessage(MessageImportance.High, $"Item: {item.ItemSpec}");
|
||||
|
||||
// Iterate through each metadata field of the item.
|
||||
foreach (string metadataName in item.MetadataNames)
|
||||
{
|
||||
string metadataValue = item.GetMetadata(metadataName);
|
||||
this.Log.LogMessage(MessageImportance.High, $" {metadataName}: {metadataValue}");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Log.LogErrorFromException(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src/ElectronNET.Build/RemoveEnvironmentVariables.cs
Normal file
42
src/ElectronNET.Build/RemoveEnvironmentVariables.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
namespace ElectronNET.Build
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
||||
public class RemoveEnvironmentVariables : Task
|
||||
{
|
||||
[Required]
|
||||
public string Variables { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(this.Variables))
|
||||
{
|
||||
this.Log.LogError("The Variables property is not set");
|
||||
return false;
|
||||
}
|
||||
|
||||
var items = this.Variables.Split(new[] { ':', ';', ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var item in items)
|
||||
{
|
||||
Environment.SetEnvironmentVariable(item.Trim(), null);
|
||||
this.Log.LogMessage("Unset environment variable: {0}", item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Log.LogErrorFromException(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
83
src/ElectronNET.Build/ReplaceMsBuildPropertiesTask.cs
Normal file
83
src/ElectronNET.Build/ReplaceMsBuildPropertiesTask.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
namespace ElectronNET.Build
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
||||
public class ReplaceTemplateTask : Task
|
||||
{
|
||||
[Required]
|
||||
public string TemplateFile { get; set; }
|
||||
|
||||
[Required]
|
||||
public string OutputFile { get; set; }
|
||||
|
||||
[Required]
|
||||
public ITaskItem[] TemplateProperties { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
////var props = this.BuildEngine9.GetGlobalProperties();
|
||||
|
||||
////var globalProperties = props
|
||||
//// .Select(e => string.Format("{0}: {1}", e.Key, e.Value));
|
||||
|
||||
////this.Log.LogMessage(MessageImportance.High, "Global Properties: \r\n" + string.Join(Environment.NewLine, globalProperties));
|
||||
|
||||
////var envVariables = Environment.GetEnvironmentVariables();
|
||||
////var envList = new List<string>();
|
||||
////foreach (var v in envVariables.Keys)
|
||||
////{
|
||||
//// envList.Add(string.Format("{0}: {1}", v, envVariables[v]));
|
||||
////}
|
||||
|
||||
////this.Log.LogMessage(MessageImportance.High, "Environment Variables: \r\n" + string.Join(Environment.NewLine, envList));
|
||||
|
||||
string content = File.ReadAllText(this.TemplateFile);
|
||||
|
||||
// Build a dictionary of property names and values.
|
||||
var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var item in this.TemplateProperties)
|
||||
{
|
||||
dict[item.ItemSpec] = item.GetMetadata("Value").Replace("\\", "\\\\");
|
||||
}
|
||||
|
||||
// Regex pattern to match placeholders like $(PropertyName)
|
||||
string pattern = @"\$\((?<prop>\w+)\)";
|
||||
content = Regex.Replace(content, pattern, match =>
|
||||
{
|
||||
string propName = match.Groups["prop"].Value;
|
||||
return dict.TryGetValue(propName, out var value) ? value : match.Value;
|
||||
});
|
||||
|
||||
// Check if the output file exists and read its content
|
||||
if (File.Exists(this.OutputFile))
|
||||
{
|
||||
string existingContent = File.ReadAllText(this.OutputFile);
|
||||
// Only write the file if the content has changed
|
||||
if (existingContent != content)
|
||||
{
|
||||
File.WriteAllText(this.OutputFile, content);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write the transformed content to the output file if it doesn't exist
|
||||
File.WriteAllText(this.OutputFile, content);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Log.LogErrorFromException(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user