-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # README.md
- Loading branch information
Showing
17 changed files
with
855 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
*.userprefs | ||
|
||
# Build results | ||
/[Bb]uild/ | ||
[Dd]ebug/ | ||
[Dd]ebugPublic/ | ||
[Rr]elease/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.IO; | ||
using System.Xml; | ||
using Mono.Cecil; | ||
|
||
namespace LinXmlGeneration | ||
{ | ||
internal static class Generation | ||
{ | ||
private static void ProcessType(XmlDocument doc, XmlElement element, TypeDefinition type) | ||
{ | ||
if(type.FullName == "<Module>") return; | ||
var typeNode = doc.CreateElement("", "type", ""); | ||
typeNode.SetAttribute("fullname", type.FullName); | ||
typeNode.SetAttribute("preserve", "all"); | ||
element.AppendChild(typeNode); | ||
} | ||
|
||
private static void ProcessAssembly(XmlDocument doc, XmlElement element, AssemblyDefinition assembly) | ||
{ | ||
var asmNode = doc.CreateElement("", "assembly", ""); | ||
asmNode.SetAttribute("fullname", assembly.Name.Name); | ||
asmNode.SetAttribute("preserve", "all"); | ||
element.AppendChild(asmNode); | ||
var types = assembly.MainModule.GetTypes(); | ||
|
||
foreach (var type in types) | ||
{ | ||
ProcessType(doc, asmNode, type); | ||
} | ||
} | ||
|
||
|
||
public static void Generate(string output, AssemblyDefinition[] assemblies) | ||
{ | ||
var file = output; | ||
|
||
var xmlDoc = new XmlDocument(); | ||
var link = xmlDoc.CreateElement( "", "linker", "" ); | ||
xmlDoc.AppendChild( link ); | ||
|
||
var xmlDeclaration = xmlDoc.CreateXmlDeclaration( "1.0", "UTF-8", null ); | ||
xmlDoc.InsertBefore( xmlDeclaration, link ); | ||
|
||
for (var i = 0; i <= assemblies.Length - 1; i++) | ||
{ | ||
ProcessAssembly(xmlDoc, link, assemblies[i]); | ||
} | ||
|
||
if (File.Exists(file)) | ||
{ | ||
File.Delete(file); | ||
} | ||
|
||
xmlDoc.Save(file); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Microsoft.Build.Framework; | ||
using Mono.Cecil; | ||
|
||
namespace LinXmlGeneration | ||
{ | ||
public class LinXmlGenerationTask: ITask | ||
{ | ||
private string target; | ||
[Required] | ||
public string Target | ||
{ | ||
get => target; | ||
set => target = value; | ||
} | ||
|
||
private string dlls; | ||
[Required] | ||
public string Dlls | ||
{ | ||
get => dlls; | ||
set => dlls = value; | ||
} | ||
|
||
private IBuildEngine engine; | ||
public IBuildEngine BuildEngine | ||
{ | ||
get { return engine; } | ||
set { engine = value; } | ||
} | ||
|
||
|
||
private ITaskHost host; | ||
public ITaskHost HostObject | ||
{ | ||
get { return host; } | ||
set { host = value; } | ||
} | ||
|
||
public bool Execute() | ||
{ | ||
engine.LogMessageEvent(new BuildMessageEventArgs( | ||
$"Execute for: '{target}', with assemblies '{dlls}'", string.Empty, nameof(LinXmlGenerationTask), MessageImportance.High)); | ||
|
||
var assemblies = new List<AssemblyDefinition>(); | ||
|
||
var dllPaths = dlls | ||
.Split(';') | ||
.Select(s => s?.Trim()) | ||
.Where(s => !string.IsNullOrEmpty(s)) | ||
.Where(File.Exists).ToArray(); | ||
|
||
|
||
for (var i = 0; i <= dllPaths.Length - 1; i++) | ||
{ | ||
try | ||
{ | ||
assemblies.Add(AssemblyDefinition.ReadAssembly(dllPaths[i])); | ||
} | ||
catch | ||
{ | ||
engine.LogMessageEvent(new BuildMessageEventArgs( | ||
$"Error occured while try load assembly from '{dllPaths[i]}'", string.Empty, nameof(LinXmlGenerationTask), MessageImportance.High)); | ||
} | ||
} | ||
|
||
try | ||
{ | ||
Generation.Generate(target, assemblies.ToArray()); | ||
} | ||
finally | ||
{ | ||
for (var i = 0; i <= assemblies.Count - 1; i++) | ||
{ | ||
assemblies[i]?.Dispose(); | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{41B6E2F9-FB82-4120-9809-BF17E9634712}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>LinkerGenerator</RootNamespace> | ||
<AssemblyName>LinkXmlGenerator</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<HintPath>..\packages\Microsoft.Build.15.9.20\lib\net46\Microsoft.Build.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<HintPath>..\packages\Microsoft.Build.Framework.15.9.20\lib\net46\Microsoft.Build.Framework.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.Setup.Configuration.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<HintPath>..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.1.16.30\lib\net35\Microsoft.VisualStudio.Setup.Configuration.Interop.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Mono.Cecil, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e"> | ||
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Mono.Cecil.Mdb, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e"> | ||
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Mdb.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Mono.Cecil.Pdb, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e"> | ||
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Pdb.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Mono.Cecil.Rocks, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e"> | ||
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Rocks.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="mscorlib" /> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Configuration" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.IO.Compression, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> | ||
<HintPath>..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Threading.Tasks.Dataflow, Version=4.5.24.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<HintPath>..\packages\System.Threading.Tasks.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Xaml" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Generation.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="LinXmlGenerationTask.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("LinkXmlGenerator")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("LinkXmlGenerator")] | ||
[assembly: AssemblyCopyright("Copyright © 2019")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("41B6E2F9-FB82-4120-9809-BF17E9634712")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Microsoft.Build" version="15.9.20" targetFramework="net471" /> | ||
<package id="Microsoft.Build.Framework" version="15.9.20" targetFramework="net471" /> | ||
<package id="Microsoft.VisualStudio.Setup.Configuration.Interop" version="1.16.30" targetFramework="net471" developmentDependency="true" /> | ||
<package id="Mono.Cecil" version="0.10.1" targetFramework="net471" /> | ||
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net471" /> | ||
<package id="System.IO.Compression" version="4.3.0" targetFramework="net471" /> | ||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net471" /> | ||
<package id="System.Threading.Tasks.Dataflow" version="4.5.24" targetFramework="net471" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.