From be5ac7d9c336f1b11264f9624ca8681086b25a28 Mon Sep 17 00:00:00 2001 From: "Arsen.Shnurkov" Date: Sun, 8 Jan 2017 18:41:16 +0300 Subject: [PATCH 1/5] x86->AnyCPU --- mono-packaging-tools.sln | 119 +++++++++++++-------------- mpt-core.tests/mpt-core.tests.csproj | 100 +++++++++++----------- mpt-core/mpt-core.csproj | 2 +- mpt-csproj/mpt-csproj.csproj | 2 +- mpt-gitmodules/mpt-gitmodules.csproj | 8 +- mpt-machine/mpt-machine.csproj | 8 +- mpt-nuget/mpt-nuget.csproj | 8 +- mpt-sln/mpt-sln.csproj | 8 +- 8 files changed, 127 insertions(+), 128 deletions(-) diff --git a/mono-packaging-tools.sln b/mono-packaging-tools.sln index 836176e..e8713a6 100644 --- a/mono-packaging-tools.sln +++ b/mono-packaging-tools.sln @@ -1,60 +1,59 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-gitmodules", "mpt-gitmodules\mpt-gitmodules.csproj", "{620A5E2F-F8D3-487C-B52D-C7B69051A0B8}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-sln", "mpt-sln\mpt-sln.csproj", "{76939073-0E35-41AC-8DBE-48B999A46A44}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-csproj", "mpt-csproj\mpt-csproj.csproj", "{CF65E2F8-720F-455B-B3D2-89AA5FF8004F}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-machine", "mpt-machine\mpt-machine.csproj", "{FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8266A819-2E58-4D02-A938-035F8FEF6A20}" - ProjectSection(SolutionItems) = preProject - AssemblyInfo.cs = AssemblyInfo.cs - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-nuget", "mpt-nuget\mpt-nuget.csproj", "{4E519C69-F4AD-4439-B61D-5FC18D6CF835}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-core", "mpt-core\mpt-core.csproj", "{36FB2731-AAFA-4D77-B406-EC3AAEA2995F}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-core.tests", "mpt-core.tests\mpt-core.tests.csproj", "{B5CBA982-1BA0-4754-A042-958506478467}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {36FB2731-AAFA-4D77-B406-EC3AAEA2995F}.Debug|x86.ActiveCfg = Debug|Any CPU - {36FB2731-AAFA-4D77-B406-EC3AAEA2995F}.Debug|x86.Build.0 = Debug|Any CPU - {36FB2731-AAFA-4D77-B406-EC3AAEA2995F}.Release|x86.ActiveCfg = Release|Any CPU - {36FB2731-AAFA-4D77-B406-EC3AAEA2995F}.Release|x86.Build.0 = Release|Any CPU - {4E519C69-F4AD-4439-B61D-5FC18D6CF835}.Debug|x86.ActiveCfg = Debug|x86 - {4E519C69-F4AD-4439-B61D-5FC18D6CF835}.Debug|x86.Build.0 = Debug|x86 - {4E519C69-F4AD-4439-B61D-5FC18D6CF835}.Release|x86.ActiveCfg = Release|x86 - {4E519C69-F4AD-4439-B61D-5FC18D6CF835}.Release|x86.Build.0 = Release|x86 - {620A5E2F-F8D3-487C-B52D-C7B69051A0B8}.Debug|x86.ActiveCfg = Debug|x86 - {620A5E2F-F8D3-487C-B52D-C7B69051A0B8}.Debug|x86.Build.0 = Debug|x86 - {620A5E2F-F8D3-487C-B52D-C7B69051A0B8}.Release|x86.ActiveCfg = Release|x86 - {620A5E2F-F8D3-487C-B52D-C7B69051A0B8}.Release|x86.Build.0 = Release|x86 - {76939073-0E35-41AC-8DBE-48B999A46A44}.Debug|x86.ActiveCfg = Debug|x86 - {76939073-0E35-41AC-8DBE-48B999A46A44}.Debug|x86.Build.0 = Debug|x86 - {76939073-0E35-41AC-8DBE-48B999A46A44}.Release|x86.ActiveCfg = Release|x86 - {76939073-0E35-41AC-8DBE-48B999A46A44}.Release|x86.Build.0 = Release|x86 - {CF65E2F8-720F-455B-B3D2-89AA5FF8004F}.Debug|x86.ActiveCfg = Debug|Any CPU - {CF65E2F8-720F-455B-B3D2-89AA5FF8004F}.Debug|x86.Build.0 = Debug|Any CPU - {CF65E2F8-720F-455B-B3D2-89AA5FF8004F}.Release|x86.ActiveCfg = Release|Any CPU - {CF65E2F8-720F-455B-B3D2-89AA5FF8004F}.Release|x86.Build.0 = Release|Any CPU - {FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B}.Debug|x86.ActiveCfg = Debug|x86 - {FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B}.Debug|x86.Build.0 = Debug|x86 - {FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B}.Release|x86.ActiveCfg = Release|x86 - {FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B}.Release|x86.Build.0 = Release|x86 - {B5CBA982-1BA0-4754-A042-958506478467}.Debug|x86.ActiveCfg = Debug|Any CPU - {B5CBA982-1BA0-4754-A042-958506478467}.Debug|x86.Build.0 = Debug|Any CPU - {B5CBA982-1BA0-4754-A042-958506478467}.Release|x86.ActiveCfg = Release|Any CPU - {B5CBA982-1BA0-4754-A042-958506478467}.Release|x86.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-gitmodules", "mpt-gitmodules\mpt-gitmodules.csproj", "{620A5E2F-F8D3-487C-B52D-C7B69051A0B8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-sln", "mpt-sln\mpt-sln.csproj", "{76939073-0E35-41AC-8DBE-48B999A46A44}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-csproj", "mpt-csproj\mpt-csproj.csproj", "{CF65E2F8-720F-455B-B3D2-89AA5FF8004F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-machine", "mpt-machine\mpt-machine.csproj", "{FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8266A819-2E58-4D02-A938-035F8FEF6A20}" + ProjectSection(SolutionItems) = preProject + AssemblyInfo.cs = AssemblyInfo.cs + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-nuget", "mpt-nuget\mpt-nuget.csproj", "{4E519C69-F4AD-4439-B61D-5FC18D6CF835}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-core", "mpt-core\mpt-core.csproj", "{36FB2731-AAFA-4D77-B406-EC3AAEA2995F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mpt-core.tests", "mpt-core.tests\mpt-core.tests.csproj", "{B5CBA982-1BA0-4754-A042-958506478467}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AnyCPU = Debug|AnyCPU + Release|AnyCPU = Release|AnyCPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {36FB2731-AAFA-4D77-B406-EC3AAEA2995F}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {36FB2731-AAFA-4D77-B406-EC3AAEA2995F}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {36FB2731-AAFA-4D77-B406-EC3AAEA2995F}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {36FB2731-AAFA-4D77-B406-EC3AAEA2995F}.Release|AnyCPU.Build.0 = Release|Any CPU + {4E519C69-F4AD-4439-B61D-5FC18D6CF835}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {4E519C69-F4AD-4439-B61D-5FC18D6CF835}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {4E519C69-F4AD-4439-B61D-5FC18D6CF835}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {4E519C69-F4AD-4439-B61D-5FC18D6CF835}.Release|AnyCPU.Build.0 = Release|Any CPU + {620A5E2F-F8D3-487C-B52D-C7B69051A0B8}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {620A5E2F-F8D3-487C-B52D-C7B69051A0B8}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {620A5E2F-F8D3-487C-B52D-C7B69051A0B8}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {620A5E2F-F8D3-487C-B52D-C7B69051A0B8}.Release|AnyCPU.Build.0 = Release|Any CPU + {76939073-0E35-41AC-8DBE-48B999A46A44}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {76939073-0E35-41AC-8DBE-48B999A46A44}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {76939073-0E35-41AC-8DBE-48B999A46A44}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {76939073-0E35-41AC-8DBE-48B999A46A44}.Release|AnyCPU.Build.0 = Release|Any CPU + {CF65E2F8-720F-455B-B3D2-89AA5FF8004F}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {CF65E2F8-720F-455B-B3D2-89AA5FF8004F}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {CF65E2F8-720F-455B-B3D2-89AA5FF8004F}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {CF65E2F8-720F-455B-B3D2-89AA5FF8004F}.Release|AnyCPU.Build.0 = Release|Any CPU + {FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B}.Release|AnyCPU.Build.0 = Release|Any CPU + {B5CBA982-1BA0-4754-A042-958506478467}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {B5CBA982-1BA0-4754-A042-958506478467}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {B5CBA982-1BA0-4754-A042-958506478467}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {B5CBA982-1BA0-4754-A042-958506478467}.Release|AnyCPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + EndGlobalSection +EndGlobal diff --git a/mpt-core.tests/mpt-core.tests.csproj b/mpt-core.tests/mpt-core.tests.csproj index 171a675..139fc9e 100644 --- a/mpt-core.tests/mpt-core.tests.csproj +++ b/mpt-core.tests/mpt-core.tests.csproj @@ -1,51 +1,51 @@ - - - - Debug - AnyCPU - {B5CBA982-1BA0-4754-A042-958506478467} - Library - tests - mpt-core.tests - v4.5 - true - ..\mono.snk - false - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - true - bin\Release - prompt - 4 - false - - - - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - - - - - - - - - - {36FB2731-AAFA-4D77-B406-EC3AAEA2995F} - mpt-core - - - + + + + Debug + AnyCPU + {B5CBA982-1BA0-4754-A042-958506478467} + Library + tests + mpt-core.tests + v4.5 + true + ..\mono.snk + false + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + true + bin\Release + prompt + 4 + false + + + + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + + + + + + + + + + {36FB2731-AAFA-4D77-B406-EC3AAEA2995F} + mpt-core + + + \ No newline at end of file diff --git a/mpt-core/mpt-core.csproj b/mpt-core/mpt-core.csproj index 68851d0..5eedce7 100644 --- a/mpt-core/mpt-core.csproj +++ b/mpt-core/mpt-core.csproj @@ -1,5 +1,5 @@ - + Debug AnyCPU diff --git a/mpt-csproj/mpt-csproj.csproj b/mpt-csproj/mpt-csproj.csproj index a75aadc..882a08c 100644 --- a/mpt-csproj/mpt-csproj.csproj +++ b/mpt-csproj/mpt-csproj.csproj @@ -1,5 +1,5 @@ - + Debug {CF65E2F8-720F-455B-B3D2-89AA5FF8004F} diff --git a/mpt-gitmodules/mpt-gitmodules.csproj b/mpt-gitmodules/mpt-gitmodules.csproj index a55a132..2def1e6 100644 --- a/mpt-gitmodules/mpt-gitmodules.csproj +++ b/mpt-gitmodules/mpt-gitmodules.csproj @@ -1,8 +1,8 @@ - + Debug - x86 + AnyCPU {620A5E2F-F8D3-487C-B52D-C7B69051A0B8} Exe mptgitmodules @@ -10,7 +10,7 @@ v4.5 false - + true full false @@ -21,7 +21,7 @@ true ! - + pdbonly true bin\Release diff --git a/mpt-machine/mpt-machine.csproj b/mpt-machine/mpt-machine.csproj index 1cd1d0d..6b8e5a2 100644 --- a/mpt-machine/mpt-machine.csproj +++ b/mpt-machine/mpt-machine.csproj @@ -1,8 +1,8 @@ - + Debug - x86 + AnyCPU {FCEA0CC0-8C29-4EAA-AB9C-362FC7BF5F7B} Exe mptmachine @@ -12,7 +12,7 @@ 2.0 false - + true full false @@ -22,7 +22,7 @@ 4 true - + pdbonly true bin\Release diff --git a/mpt-nuget/mpt-nuget.csproj b/mpt-nuget/mpt-nuget.csproj index 94563ff..763a48d 100644 --- a/mpt-nuget/mpt-nuget.csproj +++ b/mpt-nuget/mpt-nuget.csproj @@ -1,8 +1,8 @@ - + Debug - x86 + AnyCPU {4E519C69-F4AD-4439-B61D-5FC18D6CF835} Exe mptnuget @@ -10,7 +10,7 @@ v4.5 false - + true full false @@ -21,7 +21,7 @@ true x86 - + full true bin\Release diff --git a/mpt-sln/mpt-sln.csproj b/mpt-sln/mpt-sln.csproj index 12093f2..2a91c5b 100644 --- a/mpt-sln/mpt-sln.csproj +++ b/mpt-sln/mpt-sln.csproj @@ -1,8 +1,8 @@ - + Debug - x86 + AnyCPU {76939073-0E35-41AC-8DBE-48B999A46A44} Exe mptsln @@ -10,7 +10,7 @@ v4.5 false - + true full false @@ -20,7 +20,7 @@ 4 true - + pdbonly true bin\Release From 863a5dd0860f78ed198ae6a041134b4156635708 Mon Sep 17 00:00:00 2001 From: "Arsen.Shnurkov" Date: Sun, 15 Jan 2017 14:36:15 +0300 Subject: [PATCH 2/5] adding tasks programmatically --- mpt-core/03_msbuild/ICan.cs | 21 ++ mpt-core/03_msbuild/MSBuildFile.cs | 232 ++++++++++++++++++ mpt-core/03_msbuild/MSBuildImport.cs | 32 +++ mpt-core/03_msbuild/MSBuildItem.cs | 16 ++ mpt-core/03_msbuild/MSBuildItemGroup.cs | 32 +++ mpt-core/03_msbuild/MSBuildProperty.cs | 41 ++++ mpt-core/03_msbuild/MSBuildPropertyGroup.cs | 55 +++++ mpt-core/03_msbuild/MSBuildTarget.cs | 70 ++++++ mpt-core/03_msbuild/MSBuildTask.cs | 118 +++++++++ mpt-core/03_msbuild/MSBuildTaskParameter.cs | 38 +++ mpt-core/03_msbuild/MSBuildTaskResultItem.cs | 50 ++++ .../03_msbuild/MSBuildTaskResultProperty.cs | 50 ++++ mpt-core/04_CSProj/CSharpLibraryProject.cs | 113 +++++++++ .../{CSProj => 04_CSProj}/Configuration.cs | 0 mpt-core/{sln => 04_CSProj}/ProjectTools.cs | 72 +----- mpt-core/CSProj/CSharpLibraryProject.cs | 21 -- mpt-core/mpt-core.csproj | 22 +- mpt-core/sln/SolutionTools.cs | 12 +- mpt-csproj/Program.cs | 8 +- mpt-csproj/mpt-csproj.csproj | 1 + 20 files changed, 904 insertions(+), 100 deletions(-) create mode 100644 mpt-core/03_msbuild/ICan.cs create mode 100644 mpt-core/03_msbuild/MSBuildFile.cs create mode 100644 mpt-core/03_msbuild/MSBuildImport.cs create mode 100644 mpt-core/03_msbuild/MSBuildItem.cs create mode 100644 mpt-core/03_msbuild/MSBuildItemGroup.cs create mode 100644 mpt-core/03_msbuild/MSBuildProperty.cs create mode 100644 mpt-core/03_msbuild/MSBuildPropertyGroup.cs create mode 100644 mpt-core/03_msbuild/MSBuildTarget.cs create mode 100644 mpt-core/03_msbuild/MSBuildTask.cs create mode 100644 mpt-core/03_msbuild/MSBuildTaskParameter.cs create mode 100644 mpt-core/03_msbuild/MSBuildTaskResultItem.cs create mode 100644 mpt-core/03_msbuild/MSBuildTaskResultProperty.cs create mode 100644 mpt-core/04_CSProj/CSharpLibraryProject.cs rename mpt-core/{CSProj => 04_CSProj}/Configuration.cs (100%) rename mpt-core/{sln => 04_CSProj}/ProjectTools.cs (81%) delete mode 100644 mpt-core/CSProj/CSharpLibraryProject.cs diff --git a/mpt-core/03_msbuild/ICan.cs b/mpt-core/03_msbuild/ICan.cs new file mode 100644 index 0000000..5c77b34 --- /dev/null +++ b/mpt-core/03_msbuild/ICan.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Xml; + +public interface IHaveUnderlyingNode +{ + XmlNode UnderlyingNode { get; } +} + +public interface ICanHaveProperties : IHaveUnderlyingNode +{ +} + +public interface ICanHaveItems : IHaveUnderlyingNode +{ +} + +public interface ICanBeConditional +{ + string Condition { get; set; } +} + diff --git a/mpt-core/03_msbuild/MSBuildFile.cs b/mpt-core/03_msbuild/MSBuildFile.cs new file mode 100644 index 0000000..f655a0c --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildFile.cs @@ -0,0 +1,232 @@ +using System; +using System.Collections.Generic; +using System.Xml.XPath; +using System.Xml; + +public class MSBuildFile : IDisposable +{ + public const string NamespaceName = "http://schemas.microsoft.com/developer/msbuild/2003"; + XmlDocument doc; + bool bSaveRequired = false; + string filename = null; + List importNodes = new List(); + List targetNodes = new List(); + public XmlDocument UnderlyingObject + { + get + { + return doc; + } + } + public string FileName + { + get + { + return filename; + } + set + { + filename = value; + } + } + + public MSBuildFile(XmlDocument d) + { + this.doc = d; + } + public MSBuildFile(string filename) + { + XmlDocument d = new XmlDocument(); + d.Load(filename); + this.doc = d; + FindAllImports(); + FindAllTargets(); + } + + public void Dispose() + { + if (bSaveRequired && String.IsNullOrWhiteSpace(filename) == false) + { + doc.Save(filename); + } + } + + public void AddTarget(MSBuildTarget target) + { + // it does not automatically add the new object to the document tree. + // To add the new object, one must explicitly call one of the node insert methods. + XmlNode n = target.UnderlyingObject; + XPathNavigator locator = doc.CreateNavigator(); + locator.MoveToRoot(); + XmlNode root = locator.UnderlyingObject as XmlNode; + if (locator.MoveToFirstChild() == false) + { + root.AppendChild(n); + } + else + { + while (locator.MoveToNext()) { }; + XmlNode sibling = locator.UnderlyingObject as XmlNode; + root.InsertAfter(n, sibling); + } + bSaveRequired = true; + } + + static bool IsAlreadyExists(string import_name, XmlNamespaceManager xmlNamespaceManager, XPathNavigator navigator) + { + var xpath1 = "/ns:Project/ns:Import[@Project='" + import_name + "']"; + XPathExpression expr1 = navigator.Compile(xpath1); + expr1.SetContext(xmlNamespaceManager); + var nodeIterator1 = navigator.Select(expr1); + if (nodeIterator1.Count > 0) + { + return true; + } + return false; + } + + public MSBuildImport CreateImport() + { + var result = new MSBuildImport(this); + return result; + } + + public void FindAllImports() + { + var xmlNamespaceManager = new XmlNamespaceManager(new NameTable()); + xmlNamespaceManager.AddNamespace("ns", MSBuildFile.NamespaceName); + + XPathNavigator navigator = doc.CreateNavigator(); + navigator.MoveToRoot(); + + var xpath = "/ns:Project/ns:Import[@Project]"; + XPathExpression expr = navigator.Compile(xpath); + expr.SetContext(xmlNamespaceManager); + + var nodeIterator = navigator.Select(expr); + if (nodeIterator.Count == 0) + { + return; + } + do + { + if (nodeIterator.Current is IHasXmlNode) + { + XmlElement node = (XmlElement)((IHasXmlNode)nodeIterator.Current).GetNode(); + MSBuildImport wrapperObject = new MSBuildImport(this, node); + importNodes.Add(wrapperObject); + } + } + while (nodeIterator.MoveNext()); // see also https://weblogs.asp.net/cazzu/86609 + } + + // locate if there is import of Microsoft.CSharp.targets + public MSBuildImport FindImport(string v) + { + foreach (MSBuildImport item in this.importNodes) + { + if (string.Compare(item.Project, v) == 0) + { + return item; + } + } + return null; + } + + public void InsertImport(MSBuildImport newImport) + { + if (FindImport(newImport.Project) != null) + { + return; + } + + // запомнить у себя + this.importNodes.Add(newImport); + + // у тебя в руках узел, но оне вставленный в XML-документ + XmlElement newXmlElement = newImport.UnderlyingObject; + + XPathNavigator navigator = doc.CreateNavigator(); + navigator.MoveToRoot(); + + XmlElement root = (XmlElement)navigator.UnderlyingObject; + root.AppendChild(newXmlElement); + } + + public void InsertImportAfter(MSBuildImport existingImport, MSBuildImport newImport) + { + // запомнить у себя + this.importNodes.Add(newImport); + // вставить в нижележащий слой + XmlElement existingElement = existingImport.UnderlyingObject; + XmlElement newElement = newImport.UnderlyingObject; + existingElement.ParentNode.InsertAfter(existingElement, newElement); + } + + public MSBuildTarget CreateTarget() + { + var result = new MSBuildTarget(this); + return result; + } + + public void FindAllTargets() + { + var xmlNamespaceManager = new XmlNamespaceManager(new NameTable()); + xmlNamespaceManager.AddNamespace("ns", MSBuildFile.NamespaceName); + + XPathNavigator navigator = doc.CreateNavigator(); + navigator.MoveToRoot(); + + var xpath = "/ns:Project/ns:Target[@Name]"; + XPathExpression expr = navigator.Compile(xpath); + expr.SetContext(xmlNamespaceManager); + + var nodeIterator = navigator.Select(expr); + if (nodeIterator.Count == 0) + { + return; + } + do + { + if (nodeIterator.Current is IHasXmlNode) + { + XmlElement node = (XmlElement)((IHasXmlNode)nodeIterator.Current).GetNode(); + MSBuildTarget wrapperObject = new MSBuildTarget(this, node); + targetNodes.Add(wrapperObject); + } + } + while (nodeIterator.MoveNext()); // see also https://weblogs.asp.net/cazzu/86609 + } + + public MSBuildTarget FindTarget(string v) + { + foreach (MSBuildTarget item in this.targetNodes) + { + if (string.Compare(item.Name, v) == 0) + { + return item; + } + } + return null; + } + + public void InsertTarget(MSBuildTarget newTarget) + { + if (FindTarget(newTarget.Name) != null) + { + return; + } + + // запомнить у себя + this.targetNodes.Add(newTarget); + + // у тебя в руках узел, но оне вставленный в XML-документ + XmlElement newXmlElement = newTarget.UnderlyingObject; + + XPathNavigator navigator = doc.CreateNavigator(); + navigator.MoveToRoot(); + + XmlElement root = (XmlElement)navigator.UnderlyingObject; + root.AppendChild(newXmlElement); + } +} diff --git a/mpt-core/03_msbuild/MSBuildImport.cs b/mpt-core/03_msbuild/MSBuildImport.cs new file mode 100644 index 0000000..fc25eb0 --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildImport.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Xml; + +public class MSBuildImport +{ + MSBuildFile file; + XmlElement uo; + + public XmlElement UnderlyingObject + { + get + { + return uo; + } + } + + public string Project { get { return uo.Attributes["Project"].Value; } set { uo.Attributes["Project"].Value = value; } } + + public MSBuildImport(MSBuildFile f, XmlElement el) + { + this.file = f; + uo = el; + } + + public MSBuildImport(MSBuildFile f) + { + this.file = f; + // string element = ""; + uo = (XmlElement)file.UnderlyingObject.CreateNode(XmlNodeType.Element, "Import", this.uo.NamespaceURI); + } +} diff --git a/mpt-core/03_msbuild/MSBuildItem.cs b/mpt-core/03_msbuild/MSBuildItem.cs new file mode 100644 index 0000000..905528d --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildItem.cs @@ -0,0 +1,16 @@ +using System; +using System.Xml; + +public class MSBuildItem +{ + XmlElement uo; + + public XmlElement UnderlyingObject { get { return uo; } } + + public MSBuildItem(MSBuildItemGroup parent) + { + XmlDocument doc = parent.UnderlyingObject.OwnerDocument; + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "UndefilnedItemName", doc.NamespaceURI); + } +} + diff --git a/mpt-core/03_msbuild/MSBuildItemGroup.cs b/mpt-core/03_msbuild/MSBuildItemGroup.cs new file mode 100644 index 0000000..1d4ad15 --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildItemGroup.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Xml; + +public class MSBuildItemGroup +{ + XmlElement uo; + + public XmlElement UnderlyingObject { get { return uo; } } + + IEnumerable Items { get; } + + //ICanHaveItems parent; + + public MSBuildItemGroup(ICanHaveItems parent) + { + //this.parent = parent; + XmlDocument doc = parent.UnderlyingNode.OwnerDocument; + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "UndefilnedItemName", doc.NamespaceURI); + } + + public MSBuildItem CreateItem() + { + MSBuildItem res = new MSBuildItem(this); + return res; + } + public void AppendItem(MSBuildItem item) + { + throw new NotImplementedException(); + } +} + diff --git a/mpt-core/03_msbuild/MSBuildProperty.cs b/mpt-core/03_msbuild/MSBuildProperty.cs new file mode 100644 index 0000000..4b6486c --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildProperty.cs @@ -0,0 +1,41 @@ +using System; +using System.Xml; + +public class MSBuildProperty +{ + XmlElement uo; + + public XmlElement UnderlyingObject { get { return uo; } } + + public string Name { get { return uo.LocalName; } set { SetName(value); } } + public string Value { get { return uo.Value; } set { uo.Value = value; } } + + public MSBuildProperty(MSBuildPropertyGroup parent) + { + XmlDocument doc = parent.UnderlyingObject.OwnerDocument; + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "UndefilnedPropertyName", doc.NamespaceURI); + } + + void SetName(string name) + { + // replace underlaying object to change it's name + XmlElement oldItem = uo; + XmlDocument doc = oldItem.OwnerDocument; + // replace name + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, doc.NamespaceURI); + uo.Value = oldItem.Value; + // copy attributes + foreach (XmlAttribute a in oldItem.Attributes) + { + uo.Attributes.Append((XmlAttribute)a.CloneNode(true)); + } + // copy childs + for (XmlNode child = oldItem.FirstChild; child != null; child = child.NextSibling) + { + uo.AppendChild(child.CloneNode(true)); + } + // what about node's text content ? + //uo.Value = oldItem.Value; + oldItem.ParentNode.ReplaceChild(uo, oldItem); + } +} diff --git a/mpt-core/03_msbuild/MSBuildPropertyGroup.cs b/mpt-core/03_msbuild/MSBuildPropertyGroup.cs new file mode 100644 index 0000000..6262e32 --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildPropertyGroup.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Xml; + +public class MSBuildPropertyGroup : ICanBeConditional +{ + XmlElement uo; + List properties = new List(); + + public XmlElement UnderlyingObject { get { return uo; } } + public IEnumerable Properties { get { return properties; } } + + public string Condition { get { return GetCondition(); } set { SetCondition(value); } } + + public MSBuildPropertyGroup(ICanHaveProperties parent) + { + //this.parent = parent; + XmlDocument doc = parent.UnderlyingNode.OwnerDocument; + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "PropertyGroup", doc.NamespaceURI); + } + + string GetCondition() + { + if (uo.HasAttribute("Condition") == false) return null; + return uo.Attributes["Condition"].Value; + } + + void SetCondition(string value) + { + uo.SetAttribute("Condition", value); + } + + public MSBuildProperty CreateProperty() + { + MSBuildProperty res = new MSBuildProperty(this); + return res; + } + + public void AppendProperty(MSBuildProperty item) + { + // insert on this level + this.properties.Add(item); + // insert on underlaying level + XmlNode tn = item.UnderlyingObject; + uo.AppendChild(tn); + } + + public void AddProperty(string name, string val) + { + MSBuildProperty prop = this.CreateProperty(); + prop.Name = name; + prop.Value = val; + this.AppendProperty(prop); + } +} diff --git a/mpt-core/03_msbuild/MSBuildTarget.cs b/mpt-core/03_msbuild/MSBuildTarget.cs new file mode 100644 index 0000000..2b50eea --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildTarget.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Xml; + +public class MSBuildTarget : ICanHaveProperties, ICanHaveItems +{ + MSBuildFile file; + XmlElement uo; + List propertyGroups = new List(); + List tasks = new List(); + List items = new List(); + + public string Name { get { return uo.Attributes["Name"].Value; } set { uo.Attributes["Name"].Value = value; } } + public IEnumerable Tasks { get { return tasks; } } + public XmlElement UnderlyingObject { get { return uo; } } + public XmlNode UnderlyingNode { get { return UnderlyingObject; } } + public IEnumerable PropertyGroups {get { return propertyGroups; } } + public IEnumerable Items { get { return items; } } + + public MSBuildTarget(MSBuildFile f) + { + this.file = f; + uo = (XmlElement)file.UnderlyingObject.CreateNode(XmlNodeType.Element, "Target", this.uo.NamespaceURI); + } + + public MSBuildTarget(MSBuildFile f, XmlElement el) + { + this.file = f; + uo = el; + } + + public MSBuildTask CreateTask() + { + MSBuildTask res = new MSBuildTask(this); + return res; + } + + public MSBuildPropertyGroup CreatePropertyGroup() + { + MSBuildPropertyGroup res = new MSBuildPropertyGroup(this); + return res; + } + + public void AppendTask(MSBuildTask task) + { + // insert on this level + this.tasks.Add(task); + // insert on underlaying level + XmlNode tn = task.UnderlyingObject; + uo.AppendChild(tn); + } + + public void AppendPropertyGroup(MSBuildPropertyGroup item) + { + // insert on this level + this.propertyGroups.Add(item); + // insert on underlaying level + XmlNode tn = item.UnderlyingObject; + uo.AppendChild(tn); + } + + public void AppendItem(MSBuildItem item) + { + // insert on this level + this.items.Add(item); + // insert on underlaying level + XmlNode tn = item.UnderlyingObject; + uo.AppendChild(tn); + } +} diff --git a/mpt-core/03_msbuild/MSBuildTask.cs b/mpt-core/03_msbuild/MSBuildTask.cs new file mode 100644 index 0000000..71146d0 --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildTask.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Xml; + +public class MSBuildTask : ICanBeConditional +{ + MSBuildTarget parent; + XmlElement uo; + List parameters = new List(); + List resultProperties = new List(); + List resultItems = new List(); + public XmlNode UnderlyingObject + { + get + { + return uo; + } + } + + public string Condition { get { return GetCondition(); } set { SetCondition(value); } } + + public string Name { get { return uo.LocalName; } set { SetName(value); } } + + public MSBuildTask(MSBuildTarget p) + { + string name = "NoXmlElementName"; + this.parent = p; + XmlDocument doc = parent.UnderlyingObject.OwnerDocument; + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, doc.NamespaceURI); + } + + void SetName(string name) + { + // replace underlaying object to change it's name + XmlElement oldItem = uo; + XmlDocument doc = oldItem.OwnerDocument; + // replace name + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, doc.NamespaceURI); + uo.Value = oldItem.Value; + // copy attributes + foreach (XmlAttribute a in oldItem.Attributes) + { + uo.Attributes.Append((XmlAttribute)a.CloneNode(true)); + } + // copy childs + for (XmlNode child = oldItem.FirstChild; child != null; child = child.NextSibling) + { + uo.AppendChild(child.CloneNode(true)); + } + // what about node's text content ? + //uo.Value = oldItem.Value; + oldItem.ParentNode.ReplaceChild(uo, oldItem); + } + + public MSBuildTaskParameter CreateParameter() + { + MSBuildTaskParameter res = new MSBuildTaskParameter(this); + return res; + } + + public MSBuildTaskResultProperty CreateResultProperty() + { + MSBuildTaskResultProperty res = new MSBuildTaskResultProperty(this); + return res; + } + + public MSBuildTaskResultItem CreateResultItem() + { + MSBuildTaskResultItem res = new MSBuildTaskResultItem(this); + return res; + } + + public void AppendParameter(MSBuildTaskParameter attribute) + { + // insert on this level + this.parameters.Add(attribute); + // insert on underlaying level + XmlAttribute tn = attribute.UnderlyingObject; + uo.SetAttributeNode(tn); + } + + public void AppendResultProperty(MSBuildTaskResultProperty subNode) + { + // insert on this level + this.resultProperties.Add(subNode); + // insert on underlaying level + XmlNode tn = subNode.UnderlyingObject; + uo.AppendChild(tn); + } + + public void AppendResultItem(MSBuildTaskResultItem subNode) + { + // insert on this level + this.resultItems.Add(subNode); + // insert on underlaying level + XmlNode tn = subNode.UnderlyingObject; + uo.AppendChild(tn); + } + + public void AddParameter(string name, string val) + { + MSBuildTaskParameter parameter = this.CreateParameter(); + parameter.Name = name; + parameter.Value = val; + this.AppendParameter(parameter); + } + + string GetCondition() + { + if (uo.HasAttribute("Condition") == false) return null; + return uo.Attributes["Condition"].Value; + } + + void SetCondition(string value) + { + uo.SetAttribute("Condition", value); + } +} diff --git a/mpt-core/03_msbuild/MSBuildTaskParameter.cs b/mpt-core/03_msbuild/MSBuildTaskParameter.cs new file mode 100644 index 0000000..bb88a73 --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildTaskParameter.cs @@ -0,0 +1,38 @@ +using System; +using System.Xml; + +public class MSBuildTaskParameter +{ + // https://github.com/mono/mono/blob/master/mcs/class/referencesource/System.Xml/System/Xml/Dom/XmlAttribute.cs + XmlAttribute uo; + MSBuildTask parent; + + public XmlAttribute UnderlyingObject + { + get + { + return uo; + } + } + + public string Name { get { return uo.LocalName; } set { SetName(value); } } + public string Value { get { return uo.Value; } set { uo.Value = value; } } + + public MSBuildTaskParameter(MSBuildTask p) + { + string name = "NoAttributeNameGiven"; + this.parent = p; + XmlDocument doc = parent.UnderlyingObject.OwnerDocument; + uo = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, name, doc.NamespaceURI); + } + + void SetName(string name) + { + // replace underlaying object to change it's name + XmlAttribute oldAttr = uo; + XmlDocument doc = oldAttr.OwnerDocument; + uo = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, name, doc.NamespaceURI); + uo.Value = oldAttr.Value; + oldAttr.ParentNode.ReplaceChild(uo, oldAttr); + } +} diff --git a/mpt-core/03_msbuild/MSBuildTaskResultItem.cs b/mpt-core/03_msbuild/MSBuildTaskResultItem.cs new file mode 100644 index 0000000..fae1689 --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildTaskResultItem.cs @@ -0,0 +1,50 @@ +using System; +using System.Xml; + +public class MSBuildTaskResultItem +{ + // https://github.com/mono/mono/blob/master/mcs/class/referencesource/System.Xml/System/Xml/Dom/XmlAttribute.cs + XmlElement uo; + MSBuildTask parent; + + public XmlElement UnderlyingObject + { + get + { + return uo; + } + } + + public string TaskParameter { get { return uo.Attributes["TaskParameter"].Value; } set { uo.Attributes["TaskParameter"].Value = value; } } + public string ItemName { get { return uo.Attributes["ItemName"].Value; } set { uo.Attributes["ItemName"].Value = value; } } + + public MSBuildTaskResultItem(MSBuildTask p) + { + this.parent = p; + XmlDocument doc = parent.UnderlyingObject.OwnerDocument; + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "Output", doc.NamespaceURI); + } + + void SetName(string name) + { + // replace underlaying object to change it's name + XmlElement oldItem = uo; + XmlDocument doc = oldItem.OwnerDocument; + // replace name + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, doc.NamespaceURI); + uo.Value = oldItem.Value; + // copy attributes + foreach (XmlAttribute a in oldItem.Attributes) + { + uo.Attributes.Append((XmlAttribute)a.CloneNode(true)); + } + // copy childs + for (XmlNode child = oldItem.FirstChild; child != null; child = child.NextSibling) + { + uo.AppendChild(child.CloneNode(true)); + } + // what about node's text content ? + //uo.Value = oldItem.Value; + oldItem.ParentNode.ReplaceChild(uo, oldItem); + } +} diff --git a/mpt-core/03_msbuild/MSBuildTaskResultProperty.cs b/mpt-core/03_msbuild/MSBuildTaskResultProperty.cs new file mode 100644 index 0000000..ddc50bf --- /dev/null +++ b/mpt-core/03_msbuild/MSBuildTaskResultProperty.cs @@ -0,0 +1,50 @@ +using System; +using System.Xml; + +public class MSBuildTaskResultProperty +{ + // https://github.com/mono/mono/blob/master/mcs/class/referencesource/System.Xml/System/Xml/Dom/XmlAttribute.cs + XmlElement uo; + MSBuildTask parent; + + public XmlElement UnderlyingObject + { + get + { + return uo; + } + } + + public string TaskParameter { get { return uo.Attributes["TaskParameter"].Value; } set { uo.Attributes["TaskParameter"].Value = value; } } + public string Value { get { return uo.Value; } set { uo.Value = value; } } + + public MSBuildTaskResultProperty(MSBuildTask p) + { + this.parent = p; + XmlDocument doc = parent.UnderlyingObject.OwnerDocument; + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "Output", doc.NamespaceURI); + } + + void SetName(string name) + { + // replace underlaying object to change it's name + XmlElement oldItem = uo; + XmlDocument doc = oldItem.OwnerDocument; + // replace name + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, doc.NamespaceURI); + uo.Value = oldItem.Value; + // copy attributes + foreach (XmlAttribute a in oldItem.Attributes) + { + uo.Attributes.Append((XmlAttribute)a.CloneNode(true)); + } + // copy childs + for (XmlNode child = oldItem.FirstChild; child != null; child = child.NextSibling) + { + uo.AppendChild(child.CloneNode(true)); + } + // what about node's text content ? + //uo.Value = oldItem.Value; + oldItem.ParentNode.ReplaceChild(uo, oldItem); + } +} diff --git a/mpt-core/04_CSProj/CSharpLibraryProject.cs b/mpt-core/04_CSProj/CSharpLibraryProject.cs new file mode 100644 index 0000000..8ee06fb --- /dev/null +++ b/mpt-core/04_CSProj/CSharpLibraryProject.cs @@ -0,0 +1,113 @@ +using System; + +public class CSharpLibraryProject : IDisposable +{ + MSBuildFile uo; + + ConfigurationHashList configurations = null; + public ConfigurationHashList Configurations { get { return configurations; } } + + public string FileName { get { return uo.FileName; } set { uo.FileName = value; } } + + public CSharpLibraryProject(string csproj_file) + { + configurations = new ConfigurationHashList(this); + uo = new MSBuildFile(csproj_file); + } + + public void Dispose() + { + uo.Dispose(); + } + + public void InjectProjectImport(string import_name) + { + // construct new import + MSBuildImport newImport = uo.CreateImport(); + newImport.Project = import_name; + // insert import + MSBuildImport existingImport = uo.FindImport("$(MSBuildBinPath)\\Microsoft.CSharp.targets"); + if (existingImport == null) + { + uo.InsertImport(newImport); + } + else + { + uo.InsertImportAfter(existingImport, newImport); + } + } + + public void InjectVersioning() + { + /* + + + + + + + */ + MSBuildTarget targ = uo.CreateTarget(); + targ.Name = "MyAssemblyVersion"; + { + MSBuildTask task = targ.CreateTask(); + task.Name = "MakeDir"; + task.AddParameter("Directories", "$(IntermediateOutputPath)"); + targ.AppendTask(task); + } + { + MSBuildTask task = targ.CreateTask(); + task.Name = "AssemblyInfo"; + task.AddParameter("CodeLanguage", "CS"); + + task.AddParameter("AssemblyVersion", "$(VersionNumber)"); // System.Reflection.AssemblyVersion + task.AddParameter("AssemblyFileVersion", "$(VersionNumber)"); // System.Reflection.AssemblyFileVersion + task.AddParameter("AssemblyInformationalVersion", "$(VersionNumber)"); // System.Reflection.AssemblyInformationalVersion + + task.AddParameter("OutputFile", "$(IntermediateOutputPath)AssemblyVersion.Generated.cs"); + { + MSBuildTaskResultItem resultItem = task.CreateResultItem(); + resultItem.TaskParameter = "OutputFile"; + resultItem.ItemName = "Compile"; + task.AppendResultItem(resultItem); + } + targ.AppendTask(task); + } + uo.InsertTarget(targ); + } + + // http://stackoverflow.com/questions/30943342/how-to-use-internalsvisibleto-attribute-with-strongly-named-assembly + public void InjectInternalsVisibleTo(string assemblyName, string assemblyPublicKey) + { + MSBuildTarget targ = uo.CreateTarget(); + targ.Name = "MyInsertInternalsTo"; + { + MSBuildPropertyGroup group = targ.CreatePropertyGroup(); + group.Condition = " '$(VersionNumber)' == '' "; + group.AddProperty("VersionNumber", "1.0.0.0"); + targ.AppendPropertyGroup(group); + } + { + MSBuildTask task = targ.CreateTask(); // '$(SignAssembly)' == 'true' + task.Name = "AssemblyInfo"; + task.Condition = "'$(SignAssembly)' == 'true'"; + task.AddParameter("InternalsVisibleTo", assemblyName + ", PublicKey=" + assemblyPublicKey); + task.AddParameter("OutputFile", "$(IntermediateOutputPath)" + assemblyName + ".IVT.Generated.cs"); + targ.AppendTask(task); + } + { + MSBuildTask task = targ.CreateTask(); // '$(SignAssembly)' == 'false' + task.Name = "AssemblyInfo"; + task.Condition = "'$(SignAssembly)' != 'true'"; + task.AddParameter("InternalsVisibleTo", assemblyName); + task.AddParameter("OutputFile", "$(IntermediateOutputPath)" + assemblyName + ".IVT.Generated.cs"); + targ.AppendTask(task); + } + uo.InsertTarget(targ); + } +} diff --git a/mpt-core/CSProj/Configuration.cs b/mpt-core/04_CSProj/Configuration.cs similarity index 100% rename from mpt-core/CSProj/Configuration.cs rename to mpt-core/04_CSProj/Configuration.cs diff --git a/mpt-core/sln/ProjectTools.cs b/mpt-core/04_CSProj/ProjectTools.cs similarity index 81% rename from mpt-core/sln/ProjectTools.cs rename to mpt-core/04_CSProj/ProjectTools.cs index 47bf5d4..eb73b98 100644 --- a/mpt-core/sln/ProjectTools.cs +++ b/mpt-core/04_CSProj/ProjectTools.cs @@ -8,7 +8,6 @@ public class ProjectTools { - private const string namespaceName = "http://schemas.microsoft.com/developer/msbuild/2003"; public static void DumpFiles(string projectFilename, string baseDirectory) { List files = new List(); @@ -16,7 +15,7 @@ public static void DumpFiles(string projectFilename, string baseDirectory) var stream = new MemoryStream(File.ReadAllBytes(projectFilename)); // cache file in memoty var document = XDocument.Load(stream); var xmlNamespaceManager = new XmlNamespaceManager(new NameTable()); - xmlNamespaceManager.AddNamespace("ns", namespaceName); + xmlNamespaceManager.AddNamespace("ns", MSBuildFile.NamespaceName); IEnumerable listOfSourceFiles = document.XPathSelectElements("/ns:Project/ns:ItemGroup/ns:Compile[@Include]", xmlNamespaceManager); foreach (var el in listOfSourceFiles) { @@ -61,7 +60,7 @@ public static void DumpRefs(string projectFilename, string baseDirectory) var stream = new MemoryStream(File.ReadAllBytes(projectFilename)); // cache file in memoty var document = XDocument.Load(stream); var xmlNamespaceManager = new XmlNamespaceManager(new NameTable()); - xmlNamespaceManager.AddNamespace("ns", namespaceName); + xmlNamespaceManager.AddNamespace("ns", MSBuildFile.NamespaceName); IEnumerable listOfSourceFiles = document.XPathSelectElements("/ns:Project/ns:ItemGroup/ns:Reference[@Include]", xmlNamespaceManager); foreach (var el in listOfSourceFiles) { @@ -77,7 +76,7 @@ public static void DumpProjRefs(string projectFilename, string baseDirectory) var stream = new MemoryStream(File.ReadAllBytes(projectFilename)); // cache file in memoty var document = XDocument.Load(stream); var xmlNamespaceManager = new XmlNamespaceManager(new NameTable()); - xmlNamespaceManager.AddNamespace("ns", namespaceName); + xmlNamespaceManager.AddNamespace("ns", MSBuildFile.NamespaceName); IEnumerable listOfSourceFiles = document.XPathSelectElements("/ns:Project/ns:ItemGroup/ns:ProjectReference[@Include]", xmlNamespaceManager); foreach (var el in listOfSourceFiles) { @@ -192,7 +191,7 @@ public static void RemoveSigning(string csproj_file, string as_unified_patch) var stream = new MemoryStream(File.ReadAllBytes(csproj_file)); // cache file in memoty var document = XDocument.Load(stream); var xmlNamespaceManager = new XmlNamespaceManager(new NameTable()); - xmlNamespaceManager.AddNamespace("ns", namespaceName); + xmlNamespaceManager.AddNamespace("ns", MSBuildFile.NamespaceName); // remove SignAssembly var itemsToRemove1 = new List(); @@ -263,7 +262,7 @@ public static void ReplaceReference(string csproj_file, string reference_name, b var stream = new MemoryStream(File.ReadAllBytes(csproj_file)); // cache file in memoty var document = XDocument.Load(stream); var xmlNamespaceManager = new XmlNamespaceManager(new NameTable()); - xmlNamespaceManager.AddNamespace("ns", namespaceName); + xmlNamespaceManager.AddNamespace("ns", MSBuildFile.NamespaceName); // remove ProjectReference var itemsToRemove2 = new List(); @@ -328,65 +327,4 @@ public static void ReplaceReference(string csproj_file, string reference_name, b document.Save(csproj_file); } } - - static bool IsAlreadyExists(string import_name, XmlNamespaceManager xmlNamespaceManager, XPathNavigator navigator) - { - var xpath1 = "/ns:Project/ns:Import[@Project='" + import_name + "']"; - XPathExpression expr1 = navigator.Compile(xpath1); - expr1.SetContext(xmlNamespaceManager); - var nodeIterator1 = navigator.Select(expr1); - if (nodeIterator1.Count > 0) - { - return true; - } - return false; - } - - public static void InjectProjectImport(string csproj_file, string import_name) - { - string element = ""; - - var stream = new MemoryStream(File.ReadAllBytes(csproj_file)); // cache file in memoty - var document = new XmlDocument(); - document.Load(stream); - - var xmlNamespaceManager = new XmlNamespaceManager(new NameTable()); - xmlNamespaceManager.AddNamespace("ns", namespaceName); - - // locate if there is import of Microsoft.CSharp.targets - var navigator = document.CreateNavigator(); - navigator.MoveToRoot(); - if (IsAlreadyExists(import_name, xmlNamespaceManager, navigator) == false) - { - - //var xpath1 = "/Project/Import[@Project='$(MSBuildToolsPath)\\Microsoft.CSharp.targets']"; - //var xpath2 = "/Project/Import[@Project='$(MSBuildBinPath)\\Microsoft.CSharp.targets']"; - var xpath = "/ns:Project/ns:Import[@Project='$(MSBuildBinPath)\\Microsoft.CSharp.targets']"; - XPathExpression expr = navigator.Compile(xpath); - expr.SetContext(xmlNamespaceManager); - var nodeIterator = navigator.Select(expr); - if (nodeIterator.Count == 0) - { - // Insert project import to end of file - var ce = navigator.CanEdit; - navigator.MoveToRoot(); - navigator.MoveToFirstChild(); - navigator.AppendChild(element); - } - else - { - nodeIterator.MoveNext(); - // remove comment, if it is present - XPathNavigator pn = nodeIterator.Current.CreateNavigator(); - pn.MoveToNext(); - var s = "To modify your build process, add your task inside one of the targets below and uncomment it."; - if (pn.Value.Contains(s)) - { - pn.DeleteSelf(); - } - nodeIterator.Current.InsertAfter(element); - } - document.Save(csproj_file); - } - } } diff --git a/mpt-core/CSProj/CSharpLibraryProject.cs b/mpt-core/CSProj/CSharpLibraryProject.cs deleted file mode 100644 index 476f751..0000000 --- a/mpt-core/CSProj/CSharpLibraryProject.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using CWDev.SLNTools.Core; - -public class CSharpLibraryProject : Project -{ - ConfigurationHashList configurations = null; - public ConfigurationHashList Configurations - { - get - { - return configurations; - } - } - public CSharpLibraryProject(SolutionFile container, string projectGuid, string projectTypeGuid, string projectName, string relativePath, string parentFolderGuid, IEnumerable
projectSections, IEnumerable versionControlLines, IEnumerable projectConfigurationPlatformsLines) - : base(container, projectGuid, projectTypeGuid, projectName, relativePath, parentFolderGuid, projectSections, versionControlLines, projectConfigurationPlatformsLines) - { - configurations = new ConfigurationHashList(this); - } -} - diff --git a/mpt-core/mpt-core.csproj b/mpt-core/mpt-core.csproj index 5eedce7..35b7fad 100644 --- a/mpt-core/mpt-core.csproj +++ b/mpt-core/mpt-core.csproj @@ -53,16 +53,30 @@ - - - + + + + + + + + + + + + + + + - + + + diff --git a/mpt-core/sln/SolutionTools.cs b/mpt-core/sln/SolutionTools.cs index 2969564..9e6d4ae 100644 --- a/mpt-core/sln/SolutionTools.cs +++ b/mpt-core/sln/SolutionTools.cs @@ -30,14 +30,12 @@ public static void ProcessReferences(string solutionFullPath) var projList = sln.Projects; foreach (var p in projList) { - if (p is CSharpLibraryProject) + string fileNath = p.FullPath; + Console.WriteLine(fileNath); + var cslib = new CSharpLibraryProject(fileNath); + foreach (var configuration in cslib.Configurations) { - var cslib = (CSharpLibraryProject)p; - Console.WriteLine(cslib.FullPath); - foreach (var configuration in cslib.Configurations) - { - Console.WriteLine($"{configuration.Name} -> { configuration.GetAssemblyName()}"); - } + Console.WriteLine($"{configuration.Name} -> { configuration.GetAssemblyName()}"); } } } diff --git a/mpt-csproj/Program.cs b/mpt-csproj/Program.cs index 849650a..3ef105b 100644 --- a/mpt-csproj/Program.cs +++ b/mpt-csproj/Program.cs @@ -217,7 +217,13 @@ public static int Main (string[] args) Console.WriteLine($"Injecting import of project {import_name}"); foreach (var csproj_file in listOfCsproj) { - ProjectTools.InjectProjectImport(csproj_file, import_name); + using (CSharpLibraryProject file = new CSharpLibraryProject(csproj_file)) + { + file.InjectProjectImport(import_name); + file.InjectVersioning(); + // null is ok - http://stackoverflow.com/questions/637308/why-is-adding-null-to-a-string-legal + file.InjectInternalsVisibleTo(import_name, null); + } } } return (int)ExitCode.Success; diff --git a/mpt-csproj/mpt-csproj.csproj b/mpt-csproj/mpt-csproj.csproj index 882a08c..b02265c 100644 --- a/mpt-csproj/mpt-csproj.csproj +++ b/mpt-csproj/mpt-csproj.csproj @@ -45,6 +45,7 @@ mono-options-4.4.0.0 + From c57bc97fcfaf911ffee51205b6ba83eeda8b2dd0 Mon Sep 17 00:00:00 2001 From: "Arsen.Shnurkov" Date: Thu, 19 Jan 2017 23:54:07 +0300 Subject: [PATCH 3/5] command line parameters added --- mpt-core/04_CSProj/CSharpLibraryProject.cs | 20 ++++----- mpt-core/AssemblyName/PublicKeyUtils.cs | 42 +++++++++++++++++++ mpt-core/mpt-core.csproj | 1 + mpt-csproj/Program.cs | 49 +++++++++++++++++++++- 4 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 mpt-core/AssemblyName/PublicKeyUtils.cs diff --git a/mpt-core/04_CSProj/CSharpLibraryProject.cs b/mpt-core/04_CSProj/CSharpLibraryProject.cs index 8ee06fb..d521ea7 100644 --- a/mpt-core/04_CSProj/CSharpLibraryProject.cs +++ b/mpt-core/04_CSProj/CSharpLibraryProject.cs @@ -37,7 +37,7 @@ public void InjectProjectImport(string import_name) } } - public void InjectVersioning() + public void InjectVersioning(string versionPropertyName) { /* @@ -60,14 +60,20 @@ public void InjectVersioning() task.AddParameter("Directories", "$(IntermediateOutputPath)"); targ.AppendTask(task); } + { + MSBuildPropertyGroup group = targ.CreatePropertyGroup(); + group.Condition = " '$(" + versionPropertyName + ")' == '' "; + group.AddProperty(versionPropertyName, "1.0.0.0"); + targ.AppendPropertyGroup(group); + } { MSBuildTask task = targ.CreateTask(); task.Name = "AssemblyInfo"; task.AddParameter("CodeLanguage", "CS"); - task.AddParameter("AssemblyVersion", "$(VersionNumber)"); // System.Reflection.AssemblyVersion - task.AddParameter("AssemblyFileVersion", "$(VersionNumber)"); // System.Reflection.AssemblyFileVersion - task.AddParameter("AssemblyInformationalVersion", "$(VersionNumber)"); // System.Reflection.AssemblyInformationalVersion + task.AddParameter("AssemblyVersion", "$(" + versionPropertyName + ")"); // System.Reflection.AssemblyVersion + task.AddParameter("AssemblyFileVersion", "$(" + versionPropertyName + ")"); // System.Reflection.AssemblyFileVersion + task.AddParameter("AssemblyInformationalVersion", "$(" + versionPropertyName + ")"); // System.Reflection.AssemblyInformationalVersion task.AddParameter("OutputFile", "$(IntermediateOutputPath)AssemblyVersion.Generated.cs"); { @@ -86,12 +92,6 @@ public void InjectInternalsVisibleTo(string assemblyName, string assemblyPublicK { MSBuildTarget targ = uo.CreateTarget(); targ.Name = "MyInsertInternalsTo"; - { - MSBuildPropertyGroup group = targ.CreatePropertyGroup(); - group.Condition = " '$(VersionNumber)' == '' "; - group.AddProperty("VersionNumber", "1.0.0.0"); - targ.AppendPropertyGroup(group); - } { MSBuildTask task = targ.CreateTask(); // '$(SignAssembly)' == 'true' task.Name = "AssemblyInfo"; diff --git a/mpt-core/AssemblyName/PublicKeyUtils.cs b/mpt-core/AssemblyName/PublicKeyUtils.cs new file mode 100644 index 0000000..ad2c9ae --- /dev/null +++ b/mpt-core/AssemblyName/PublicKeyUtils.cs @@ -0,0 +1,42 @@ +using System.IO; +using System.Text; + +public class PublicKeyUtils +{ + public static byte[] GetPublicKey(byte[] snk) + { + var snkp = new System.Reflection.StrongNameKeyPair(snk); + byte[] publicKey = snkp.PublicKey; + return publicKey; + } + + public static byte[] GetPublicKey(string container) + { + var snkp = new System.Reflection.StrongNameKeyPair(container); + byte[] publicKey = snkp.PublicKey; + return publicKey; + } + + public static string ByteArrayToString(byte[] ba) + { + StringBuilder hex = new StringBuilder(ba.Length * 2); + foreach (byte b in ba) + hex.AppendFormat("{0:x2}", b); + return hex.ToString(); + } + + public static string GetPublicKeyStringFromContainer(string AssemblyKeyContainerName) + { + byte[] publicKey2 = GetPublicKey(AssemblyKeyContainerName); + string output2 = ByteArrayToString(publicKey2); + return ", PublicKey=" + output2; + } + + public static string GetPublicKeyStringFromFilename(string AssemblyOriginatorKeyFile) + { + byte[] snk = File.ReadAllBytes(AssemblyOriginatorKeyFile); + byte[] publicKey1 = GetPublicKey(snk); + string output1 = ByteArrayToString(publicKey1); + return ", PublicKey=" + output1; + } +} diff --git a/mpt-core/mpt-core.csproj b/mpt-core/mpt-core.csproj index 35b7fad..88c77a7 100644 --- a/mpt-core/mpt-core.csproj +++ b/mpt-core/mpt-core.csproj @@ -70,6 +70,7 @@ + diff --git a/mpt-csproj/Program.cs b/mpt-csproj/Program.cs index 3ef105b..425849e 100644 --- a/mpt-csproj/Program.cs +++ b/mpt-csproj/Program.cs @@ -31,6 +31,10 @@ public static int Main (string[] args) string reference_name = null; bool bForceReferenceAppending = false; string import_name = null; + string version_string = null; + string friend_assembly_name = null; + string AssemblyKeyContainerName = null; + string AssemblyOriginatorKeyFile = null; var optionSet = new OptionSet() { @@ -68,6 +72,13 @@ public static int Main (string[] args) { "inject-reference=", str => { reference_name = str; bForceReferenceAppending = true; } }, // insert project import into .csproj files { "inject-import=", str => { import_name = str; } }, + // insert task for versioning into .csproj files + { "inject-versioning=", str => { version_string = str; } }, + // insert project import into .csproj files + { "inject-InternalsVisibleTo=", str => { friend_assembly_name = str; } }, + // insert project import into .csproj files + { "AssemblyKeyContainerName=", str => { AssemblyKeyContainerName = str; } }, + { "AssemblyOriginatorKeyFile=", str => { AssemblyOriginatorKeyFile = str; } }, }; var listOfUnparsedParameters = optionSet.Parse(args); @@ -220,9 +231,38 @@ public static int Main (string[] args) using (CSharpLibraryProject file = new CSharpLibraryProject(csproj_file)) { file.InjectProjectImport(import_name); - file.InjectVersioning(); + } + } + } + if (version_string != null) + { + Console.WriteLine($"Injecting version property {version_string}"); + foreach (var csproj_file in listOfCsproj) + { + using (CSharpLibraryProject file = new CSharpLibraryProject(csproj_file)) + { + file.InjectVersioning(version_string); + } + } + } + if (friend_assembly_name != null) + { + Console.WriteLine($"Injecting version property {version_string}"); + foreach (var csproj_file in listOfCsproj) + { + using (CSharpLibraryProject file = new CSharpLibraryProject(csproj_file)) + { // null is ok - http://stackoverflow.com/questions/637308/why-is-adding-null-to-a-string-legal - file.InjectInternalsVisibleTo(import_name, null); + string publicKey = null; + if (String.IsNullOrEmpty(AssemblyOriginatorKeyFile) == false) + { + publicKey = PublicKeyUtils.GetPublicKeyStringFromFilename(AssemblyOriginatorKeyFile); + } + if (String.IsNullOrEmpty(AssemblyKeyContainerName) == false ) + { + publicKey = PublicKeyUtils.GetPublicKeyStringFromContainer(AssemblyKeyContainerName); + } + file.InjectInternalsVisibleTo(import_name, publicKey); } } } @@ -252,6 +292,11 @@ public static void ShowHelp() Console.WriteLine("\tmpt-csproj --inject-reference=\"MyDll,Version,Culture,PubKeyToken\""); Console.WriteLine("\tmpt-csproj --inject-import='$(MSBuildToolsPath)\\MSBuild.Community.Tasks.Targets'"); Console.WriteLine("\t\tinserts new reference for MyDll of given version, or replaces the old one"); + Console.WriteLine("\tmpt-csproj --inject - versioning=BuildVersion"); + Console.WriteLine("\t\tinserts property with given name $(BuildVersion), and default value 1.0.0.0"); + Console.WriteLine("\tmpt-csproj --inject-InternalsVisibleTo=mytest.dll --AssemblyKeyContainerName=mono"); + Console.WriteLine("\tmpt-csproj --inject-InternalsVisibleTo=mytest.dll --AssemblyOriginatorKeyFile=mono.snk"); + Console.WriteLine("\t\tinserts InternalsVisibleToAttribute"); } static List listOfCsproj = new List(); static void AddProjectFile(string filename) From 86afe4f0ead413fe95f0ba0d2b205f2afbe10a3b Mon Sep 17 00:00:00 2001 From: "Arsen.Shnurkov" Date: Sat, 21 Jan 2017 11:17:27 +0300 Subject: [PATCH 4/5] first iteration of debugging --- mpt-core/03_msbuild/MSBuildFile.cs | 32 ++++++++++++++------- mpt-core/03_msbuild/MSBuildImport.cs | 16 +++++++++-- mpt-core/03_msbuild/MSBuildTarget.cs | 2 +- mpt-csproj/Program.cs | 43 ++++++++++++++++++++++++++-- mpt-csproj/mpt-csproj.csproj | 4 +-- 5 files changed, 78 insertions(+), 19 deletions(-) diff --git a/mpt-core/03_msbuild/MSBuildFile.cs b/mpt-core/03_msbuild/MSBuildFile.cs index f655a0c..355af36 100644 --- a/mpt-core/03_msbuild/MSBuildFile.cs +++ b/mpt-core/03_msbuild/MSBuildFile.cs @@ -39,6 +39,7 @@ public MSBuildFile(string filename) XmlDocument d = new XmlDocument(); d.Load(filename); this.doc = d; + this.filename = filename; FindAllImports(); FindAllTargets(); } @@ -108,16 +109,17 @@ public void FindAllImports() { return; } - do + while (nodeIterator.MoveNext()) { if (nodeIterator.Current is IHasXmlNode) { - XmlElement node = (XmlElement)((IHasXmlNode)nodeIterator.Current).GetNode(); - MSBuildImport wrapperObject = new MSBuildImport(this, node); + XmlNode node = ((IHasXmlNode)nodeIterator.Current).GetNode(); + XmlElement element = (XmlElement)node; + MSBuildImport wrapperObject = new MSBuildImport(this, element); importNodes.Add(wrapperObject); } } - while (nodeIterator.MoveNext()); // see also https://weblogs.asp.net/cazzu/86609 + // see also https://weblogs.asp.net/cazzu/86609 } // locate if there is import of Microsoft.CSharp.targets @@ -149,8 +151,11 @@ public void InsertImport(MSBuildImport newImport) XPathNavigator navigator = doc.CreateNavigator(); navigator.MoveToRoot(); - XmlElement root = (XmlElement)navigator.UnderlyingObject; - root.AppendChild(newXmlElement); + XmlNode root = (XmlNode)navigator.UnderlyingObject; + XmlNode lc = root.LastChild; + lc.AppendChild(newXmlElement); + + bSaveRequired = true; } public void InsertImportAfter(MSBuildImport existingImport, MSBuildImport newImport) @@ -160,7 +165,9 @@ public void InsertImportAfter(MSBuildImport existingImport, MSBuildImport newImp // вставить в нижележащий слой XmlElement existingElement = existingImport.UnderlyingObject; XmlElement newElement = newImport.UnderlyingObject; - existingElement.ParentNode.InsertAfter(existingElement, newElement); + existingElement.ParentNode.InsertAfter(newElement, existingElement); + + bSaveRequired = true; } public MSBuildTarget CreateTarget() @@ -186,16 +193,17 @@ public void FindAllTargets() { return; } - do + while (nodeIterator.MoveNext()) { if (nodeIterator.Current is IHasXmlNode) { - XmlElement node = (XmlElement)((IHasXmlNode)nodeIterator.Current).GetNode(); - MSBuildTarget wrapperObject = new MSBuildTarget(this, node); + XmlNode node = ((IHasXmlNode)nodeIterator.Current).GetNode(); + XmlElement element = (XmlElement)node; + MSBuildTarget wrapperObject = new MSBuildTarget(this, element); targetNodes.Add(wrapperObject); } } - while (nodeIterator.MoveNext()); // see also https://weblogs.asp.net/cazzu/86609 + // see also https://weblogs.asp.net/cazzu/86609 } public MSBuildTarget FindTarget(string v) @@ -228,5 +236,7 @@ public void InsertTarget(MSBuildTarget newTarget) XmlElement root = (XmlElement)navigator.UnderlyingObject; root.AppendChild(newXmlElement); + + bSaveRequired = true; } } diff --git a/mpt-core/03_msbuild/MSBuildImport.cs b/mpt-core/03_msbuild/MSBuildImport.cs index fc25eb0..222d633 100644 --- a/mpt-core/03_msbuild/MSBuildImport.cs +++ b/mpt-core/03_msbuild/MSBuildImport.cs @@ -15,7 +15,7 @@ public XmlElement UnderlyingObject } } - public string Project { get { return uo.Attributes["Project"].Value; } set { uo.Attributes["Project"].Value = value; } } + public string Project { get { return uo.Attributes["Project"].Value; } set { uo.SetAttribute("Project", value); } } public MSBuildImport(MSBuildFile f, XmlElement el) { @@ -27,6 +27,18 @@ public MSBuildImport(MSBuildFile f) { this.file = f; // string element = ""; - uo = (XmlElement)file.UnderlyingObject.CreateNode(XmlNodeType.Element, "Import", this.uo.NamespaceURI); + uo = (XmlElement)file.UnderlyingObject.CreateNode(XmlNodeType.Element, "Import", MSBuildFile.NamespaceName); } + + /*void SetProject(string value) + { + if (uo.HasAttribute("Project))" + + { + uo.Attributes["Project"].Value = value; + } + else + { + uo.SetAttribute("Project", value); + } + }*/ } diff --git a/mpt-core/03_msbuild/MSBuildTarget.cs b/mpt-core/03_msbuild/MSBuildTarget.cs index 2b50eea..a6d8bde 100644 --- a/mpt-core/03_msbuild/MSBuildTarget.cs +++ b/mpt-core/03_msbuild/MSBuildTarget.cs @@ -20,7 +20,7 @@ public class MSBuildTarget : ICanHaveProperties, ICanHaveItems public MSBuildTarget(MSBuildFile f) { this.file = f; - uo = (XmlElement)file.UnderlyingObject.CreateNode(XmlNodeType.Element, "Target", this.uo.NamespaceURI); + uo = (XmlElement)file.UnderlyingObject.CreateNode(XmlNodeType.Element, "Target", MSBuildFile.NamespaceName); } public MSBuildTarget(MSBuildFile f, XmlElement el) diff --git a/mpt-csproj/Program.cs b/mpt-csproj/Program.cs index 425849e..36449f2 100644 --- a/mpt-csproj/Program.cs +++ b/mpt-csproj/Program.cs @@ -14,8 +14,32 @@ enum ExitCode : int NoInputFileSpecified = 2, NoDataProviderNameSpecified = 3, NothingToDo = 4, + HelpOrVersion = 5, + Exception = 6, } - public static int Main (string[] args) + public static int Main(string[] args) + { + try + { + return MainProcessing(args); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + ShowVersion(); + for (int i = 0; i < args.Length; i++) + { + if (i > 0) + { + Console.Write(" "); + } + Console.Write(args[i]); + } + Console.WriteLine(); + } + return (int)ExitCode.Exception; + } + public static int MainProcessing(string[] args) { var verbose = (string)null; var remove_warnings_as_errors = (string)null; @@ -40,7 +64,8 @@ public static int Main (string[] args) { /* General options */ // output usage summary and exit - { "h|?|help", v => ShowHelp() }, + { "h|?|help", v => { ShowHelp(); System.Environment.Exit((int)ExitCode.HelpOrVersion); } }, + { "v|V|version", v => { ShowVersion(); System.Environment.Exit((int)ExitCode.HelpOrVersion); } }, // give more explainations during work { "verbose", b => verbose = b }, @@ -193,8 +218,10 @@ public static int Main (string[] args) } if (remove_warnings_as_errors != null) { + Console.WriteLine($"Removing warnings as errors"); foreach (var csproj_file in listOfCsproj) { + Console.WriteLine($"from file {csproj_file}"); if (verbose != null) { string output_or_inplace = (as_unified_patch == null) ? ", inplace conversion" : String.Format(" >> {0}", as_unified_patch); @@ -205,8 +232,10 @@ public static int Main (string[] args) } if (remove_signing != null) { + Console.WriteLine($"Removing signing"); foreach (var csproj_file in listOfCsproj) { + Console.WriteLine($"from file {csproj_file}"); if (verbose != null) { string output_or_inplace = (as_unified_patch == null) ? ", inplace conversion" : String.Format(" >> {0}", as_unified_patch); @@ -220,6 +249,7 @@ public static int Main (string[] args) Console.WriteLine($"Replacing reference {reference_name}"); foreach (var csproj_file in listOfCsproj) { + Console.WriteLine($"in file {csproj_file}"); ProjectTools.ReplaceReference(csproj_file, reference_name, bForceReferenceAppending); } } @@ -228,6 +258,7 @@ public static int Main (string[] args) Console.WriteLine($"Injecting import of project {import_name}"); foreach (var csproj_file in listOfCsproj) { + Console.WriteLine($"into file {csproj_file}"); using (CSharpLibraryProject file = new CSharpLibraryProject(csproj_file)) { file.InjectProjectImport(import_name); @@ -239,6 +270,7 @@ public static int Main (string[] args) Console.WriteLine($"Injecting version property {version_string}"); foreach (var csproj_file in listOfCsproj) { + Console.WriteLine($"into file {csproj_file}"); using (CSharpLibraryProject file = new CSharpLibraryProject(csproj_file)) { file.InjectVersioning(version_string); @@ -250,6 +282,7 @@ public static int Main (string[] args) Console.WriteLine($"Injecting version property {version_string}"); foreach (var csproj_file in listOfCsproj) { + Console.WriteLine($"into file {csproj_file}"); using (CSharpLibraryProject file = new CSharpLibraryProject(csproj_file)) { // null is ok - http://stackoverflow.com/questions/637308/why-is-adding-null-to-a-string-legal @@ -268,10 +301,14 @@ public static int Main (string[] args) } return (int)ExitCode.Success; } - public static void ShowHelp() + public static void ShowVersion() { var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Console.WriteLine($"mpt-cspoj.exe, version {version}"); + } + public static void ShowHelp() + { + ShowVersion(); Console.WriteLine("Usage: "); Console.WriteLine("\tmpt-csproj --list-refs"); Console.WriteLine("\t\tPrints references"); diff --git a/mpt-csproj/mpt-csproj.csproj b/mpt-csproj/mpt-csproj.csproj index b02265c..5643798 100644 --- a/mpt-csproj/mpt-csproj.csproj +++ b/mpt-csproj/mpt-csproj.csproj @@ -31,11 +31,11 @@ TRACE - ..\..\..\..\..\..\..\usr\share\mono-packaging-tools-0 + ..\..\..\..\..\..\..\usr\share\mono-packaging-tools\slot-0\ - + From 2f3dcbebf189dc9025de0f480b18e15fcdc813ce Mon Sep 17 00:00:00 2001 From: ArsenShnurkov Date: Sat, 21 Jan 2017 22:01:47 +0300 Subject: [PATCH 5/5] second iteration of debugging --- mpt-core/03_msbuild/MSBuildFile.cs | 52 ++++++++++++++++++- mpt-core/03_msbuild/MSBuildItem.cs | 2 +- mpt-core/03_msbuild/MSBuildItemGroup.cs | 2 +- mpt-core/03_msbuild/MSBuildProperty.cs | 16 +++--- mpt-core/03_msbuild/MSBuildPropertyGroup.cs | 2 +- mpt-core/03_msbuild/MSBuildTarget.cs | 43 ++++++++++++++- mpt-core/03_msbuild/MSBuildTask.cs | 14 ++--- mpt-core/03_msbuild/MSBuildTaskParameter.cs | 9 ++-- mpt-core/03_msbuild/MSBuildTaskResultItem.cs | 8 +-- .../03_msbuild/MSBuildTaskResultProperty.cs | 4 +- mpt-core/04_CSProj/CSharpLibraryProject.cs | 21 ++++++++ mpt-core/AssemblyName/PublicKeyUtils.cs | 4 +- mpt-csproj/Program.cs | 16 +++--- mpt-csproj/mpt-csproj.csproj | 2 +- 14 files changed, 158 insertions(+), 37 deletions(-) diff --git a/mpt-core/03_msbuild/MSBuildFile.cs b/mpt-core/03_msbuild/MSBuildFile.cs index 355af36..5ea244a 100644 --- a/mpt-core/03_msbuild/MSBuildFile.cs +++ b/mpt-core/03_msbuild/MSBuildFile.cs @@ -234,8 +234,56 @@ public void InsertTarget(MSBuildTarget newTarget) XPathNavigator navigator = doc.CreateNavigator(); navigator.MoveToRoot(); - XmlElement root = (XmlElement)navigator.UnderlyingObject; - root.AppendChild(newXmlElement); + XmlNode root = (XmlNode)navigator.UnderlyingObject; + XmlNode project = root.LastChild; + project.AppendChild(newXmlElement); + + bSaveRequired = true; + } + + public void EnsureTargetExists(string targetName) + { + if (FindTarget(targetName) != null) + { + return; + } + MSBuildTarget targ = this.CreateTarget(); + targ.Name = targetName; + InsertTarget(targ); + + bSaveRequired = true; + } + + public void AddAfterTarget(string precedingTarget, string followingTarget) + { + MSBuildTarget preceding = FindTarget(precedingTarget); + if (preceding == null) + { + throw new ApplicationException($"Target {precedingTarget} not found"); + } + MSBuildTarget following = FindTarget(followingTarget); + if (following == null) + { + throw new ApplicationException($"Target {followingTarget} not found"); + } + preceding.AddAfterTarget(following.Name); + + bSaveRequired = true; + } + + public void AddDependOnTarget(string precedingTarget, string followingTarget) + { + MSBuildTarget preceding = FindTarget(precedingTarget); + if (preceding == null) + { + throw new ApplicationException($"Target {precedingTarget} not found"); + } + MSBuildTarget following = FindTarget(followingTarget); + if (following == null) + { + throw new ApplicationException($"Target {followingTarget} not found"); + } + preceding.AddDependOnTarget(following.Name); bSaveRequired = true; } diff --git a/mpt-core/03_msbuild/MSBuildItem.cs b/mpt-core/03_msbuild/MSBuildItem.cs index 905528d..5f23feb 100644 --- a/mpt-core/03_msbuild/MSBuildItem.cs +++ b/mpt-core/03_msbuild/MSBuildItem.cs @@ -10,7 +10,7 @@ public class MSBuildItem public MSBuildItem(MSBuildItemGroup parent) { XmlDocument doc = parent.UnderlyingObject.OwnerDocument; - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "UndefilnedItemName", doc.NamespaceURI); + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "UndefilnedItemName", MSBuildFile.NamespaceName); } } diff --git a/mpt-core/03_msbuild/MSBuildItemGroup.cs b/mpt-core/03_msbuild/MSBuildItemGroup.cs index 1d4ad15..1fef884 100644 --- a/mpt-core/03_msbuild/MSBuildItemGroup.cs +++ b/mpt-core/03_msbuild/MSBuildItemGroup.cs @@ -16,7 +16,7 @@ public MSBuildItemGroup(ICanHaveItems parent) { //this.parent = parent; XmlDocument doc = parent.UnderlyingNode.OwnerDocument; - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "UndefilnedItemName", doc.NamespaceURI); + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "UndefilnedItemName", MSBuildFile.NamespaceName); } public MSBuildItem CreateItem() diff --git a/mpt-core/03_msbuild/MSBuildProperty.cs b/mpt-core/03_msbuild/MSBuildProperty.cs index 4b6486c..50b7aa5 100644 --- a/mpt-core/03_msbuild/MSBuildProperty.cs +++ b/mpt-core/03_msbuild/MSBuildProperty.cs @@ -8,12 +8,12 @@ public class MSBuildProperty public XmlElement UnderlyingObject { get { return uo; } } public string Name { get { return uo.LocalName; } set { SetName(value); } } - public string Value { get { return uo.Value; } set { uo.Value = value; } } + public string Value { get { return uo.InnerText; } set { uo.InnerText = value; } } public MSBuildProperty(MSBuildPropertyGroup parent) { XmlDocument doc = parent.UnderlyingObject.OwnerDocument; - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "UndefilnedPropertyName", doc.NamespaceURI); + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "UndefilnedPropertyName", MSBuildFile.NamespaceName); } void SetName(string name) @@ -22,8 +22,9 @@ void SetName(string name) XmlElement oldItem = uo; XmlDocument doc = oldItem.OwnerDocument; // replace name - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, doc.NamespaceURI); - uo.Value = oldItem.Value; + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, MSBuildFile.NamespaceName); + // what about node's text content ? + uo.InnerText = oldItem.InnerText; // copy attributes foreach (XmlAttribute a in oldItem.Attributes) { @@ -34,8 +35,9 @@ void SetName(string name) { uo.AppendChild(child.CloneNode(true)); } - // what about node's text content ? - //uo.Value = oldItem.Value; - oldItem.ParentNode.ReplaceChild(uo, oldItem); + if (oldItem.ParentNode != null) + { + oldItem.ParentNode.ReplaceChild(uo, oldItem); + } } } diff --git a/mpt-core/03_msbuild/MSBuildPropertyGroup.cs b/mpt-core/03_msbuild/MSBuildPropertyGroup.cs index 6262e32..adf41d8 100644 --- a/mpt-core/03_msbuild/MSBuildPropertyGroup.cs +++ b/mpt-core/03_msbuild/MSBuildPropertyGroup.cs @@ -16,7 +16,7 @@ public MSBuildPropertyGroup(ICanHaveProperties parent) { //this.parent = parent; XmlDocument doc = parent.UnderlyingNode.OwnerDocument; - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "PropertyGroup", doc.NamespaceURI); + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "PropertyGroup", MSBuildFile.NamespaceName); } string GetCondition() diff --git a/mpt-core/03_msbuild/MSBuildTarget.cs b/mpt-core/03_msbuild/MSBuildTarget.cs index a6d8bde..3cdeb77 100644 --- a/mpt-core/03_msbuild/MSBuildTarget.cs +++ b/mpt-core/03_msbuild/MSBuildTarget.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text; using System.Xml; public class MSBuildTarget : ICanHaveProperties, ICanHaveItems @@ -10,7 +11,7 @@ public class MSBuildTarget : ICanHaveProperties, ICanHaveItems List tasks = new List(); List items = new List(); - public string Name { get { return uo.Attributes["Name"].Value; } set { uo.Attributes["Name"].Value = value; } } + public string Name { get { return uo.Attributes["Name"].Value; } set { uo.SetAttribute("Name", value); } } public IEnumerable Tasks { get { return tasks; } } public XmlElement UnderlyingObject { get { return uo; } } public XmlNode UnderlyingNode { get { return UnderlyingObject; } } @@ -67,4 +68,44 @@ public void AppendItem(MSBuildItem item) XmlNode tn = item.UnderlyingObject; uo.AppendChild(tn); } + + public readonly char[] TargetSeparators = new char[] { ';' }; + + void AppendListOfTargets(string attributeName, string nameToAdd) + { + string attr = uo.GetAttribute(attributeName); + string[] targets = attr.Split(TargetSeparators); + for (int i = 0; i < targets.Length; i++) + { + if (string.Compare(targets[i], nameToAdd) == 0) + { + return; + } + } + StringBuilder res = new StringBuilder(); + for (int i = 0; i < targets.Length; i++) + { + if (i > 0) + { + res.Append(TargetSeparators); + } + res.Append(targets[i]); + } + if (res.Length > 0) + { + res.Append(TargetSeparators); + } + res.Append(nameToAdd); + uo.SetAttribute(attributeName, res.ToString()); + } + + public void AddAfterTarget(string name) + { + AppendListOfTargets("AfterTargets", name); + } + + public void AddDependOnTarget(string name) + { + AppendListOfTargets("DependsOnTargets", name); + } } diff --git a/mpt-core/03_msbuild/MSBuildTask.cs b/mpt-core/03_msbuild/MSBuildTask.cs index 71146d0..005715d 100644 --- a/mpt-core/03_msbuild/MSBuildTask.cs +++ b/mpt-core/03_msbuild/MSBuildTask.cs @@ -26,7 +26,7 @@ public MSBuildTask(MSBuildTarget p) string name = "NoXmlElementName"; this.parent = p; XmlDocument doc = parent.UnderlyingObject.OwnerDocument; - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, doc.NamespaceURI); + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, MSBuildFile.NamespaceName); } void SetName(string name) @@ -35,8 +35,9 @@ void SetName(string name) XmlElement oldItem = uo; XmlDocument doc = oldItem.OwnerDocument; // replace name - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, doc.NamespaceURI); - uo.Value = oldItem.Value; + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, MSBuildFile.NamespaceName); + // what about node's text content ? + uo.InnerText = oldItem.InnerText; // copy attributes foreach (XmlAttribute a in oldItem.Attributes) { @@ -47,9 +48,10 @@ void SetName(string name) { uo.AppendChild(child.CloneNode(true)); } - // what about node's text content ? - //uo.Value = oldItem.Value; - oldItem.ParentNode.ReplaceChild(uo, oldItem); + if (oldItem.ParentNode != null) + { + oldItem.ParentNode.ReplaceChild(uo, oldItem); + } } public MSBuildTaskParameter CreateParameter() diff --git a/mpt-core/03_msbuild/MSBuildTaskParameter.cs b/mpt-core/03_msbuild/MSBuildTaskParameter.cs index bb88a73..d88b6a8 100644 --- a/mpt-core/03_msbuild/MSBuildTaskParameter.cs +++ b/mpt-core/03_msbuild/MSBuildTaskParameter.cs @@ -23,7 +23,7 @@ public MSBuildTaskParameter(MSBuildTask p) string name = "NoAttributeNameGiven"; this.parent = p; XmlDocument doc = parent.UnderlyingObject.OwnerDocument; - uo = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, name, doc.NamespaceURI); + uo = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, name, null/*MSBuildFile.NamespaceName*/); } void SetName(string name) @@ -31,8 +31,11 @@ void SetName(string name) // replace underlaying object to change it's name XmlAttribute oldAttr = uo; XmlDocument doc = oldAttr.OwnerDocument; - uo = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, name, doc.NamespaceURI); + uo = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, name, null/*MSBuildFile.NamespaceName*/); uo.Value = oldAttr.Value; - oldAttr.ParentNode.ReplaceChild(uo, oldAttr); + if (oldAttr.ParentNode != null) + { + oldAttr.ParentNode.ReplaceChild(uo, oldAttr); + } } } diff --git a/mpt-core/03_msbuild/MSBuildTaskResultItem.cs b/mpt-core/03_msbuild/MSBuildTaskResultItem.cs index fae1689..767b39f 100644 --- a/mpt-core/03_msbuild/MSBuildTaskResultItem.cs +++ b/mpt-core/03_msbuild/MSBuildTaskResultItem.cs @@ -15,14 +15,14 @@ public XmlElement UnderlyingObject } } - public string TaskParameter { get { return uo.Attributes["TaskParameter"].Value; } set { uo.Attributes["TaskParameter"].Value = value; } } - public string ItemName { get { return uo.Attributes["ItemName"].Value; } set { uo.Attributes["ItemName"].Value = value; } } + public string TaskParameter { get { return uo.Attributes["TaskParameter"].Value; } set { uo.SetAttribute("TaskParameter", value); } } + public string ItemName { get { return uo.Attributes["ItemName"].Value; } set { uo.SetAttribute("ItemName", value); } } public MSBuildTaskResultItem(MSBuildTask p) { this.parent = p; XmlDocument doc = parent.UnderlyingObject.OwnerDocument; - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "Output", doc.NamespaceURI); + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "Output", MSBuildFile.NamespaceName); } void SetName(string name) @@ -31,7 +31,7 @@ void SetName(string name) XmlElement oldItem = uo; XmlDocument doc = oldItem.OwnerDocument; // replace name - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, doc.NamespaceURI); + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, MSBuildFile.NamespaceName); uo.Value = oldItem.Value; // copy attributes foreach (XmlAttribute a in oldItem.Attributes) diff --git a/mpt-core/03_msbuild/MSBuildTaskResultProperty.cs b/mpt-core/03_msbuild/MSBuildTaskResultProperty.cs index ddc50bf..761c89c 100644 --- a/mpt-core/03_msbuild/MSBuildTaskResultProperty.cs +++ b/mpt-core/03_msbuild/MSBuildTaskResultProperty.cs @@ -22,7 +22,7 @@ public MSBuildTaskResultProperty(MSBuildTask p) { this.parent = p; XmlDocument doc = parent.UnderlyingObject.OwnerDocument; - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "Output", doc.NamespaceURI); + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "Output", MSBuildFile.NamespaceName); } void SetName(string name) @@ -31,7 +31,7 @@ void SetName(string name) XmlElement oldItem = uo; XmlDocument doc = oldItem.OwnerDocument; // replace name - uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, doc.NamespaceURI); + uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, name, MSBuildFile.NamespaceName); uo.Value = oldItem.Value; // copy attributes foreach (XmlAttribute a in oldItem.Attributes) diff --git a/mpt-core/04_CSProj/CSharpLibraryProject.cs b/mpt-core/04_CSProj/CSharpLibraryProject.cs index d521ea7..ce142d5 100644 --- a/mpt-core/04_CSProj/CSharpLibraryProject.cs +++ b/mpt-core/04_CSProj/CSharpLibraryProject.cs @@ -84,7 +84,9 @@ public void InjectVersioning(string versionPropertyName) } targ.AppendTask(task); } + uo.EnsureTargetExists("BeforeBuild"); uo.InsertTarget(targ); + uo.AddDependOnTarget("BeforeBuild", targ.Name); } // http://stackoverflow.com/questions/30943342/how-to-use-internalsvisibleto-attribute-with-strongly-named-assembly @@ -95,19 +97,38 @@ public void InjectInternalsVisibleTo(string assemblyName, string assemblyPublicK { MSBuildTask task = targ.CreateTask(); // '$(SignAssembly)' == 'true' task.Name = "AssemblyInfo"; + task.AddParameter("CodeLanguage", "CS"); + task.Condition = "'$(SignAssembly)' == 'true'"; task.AddParameter("InternalsVisibleTo", assemblyName + ", PublicKey=" + assemblyPublicKey); task.AddParameter("OutputFile", "$(IntermediateOutputPath)" + assemblyName + ".IVT.Generated.cs"); + { + MSBuildTaskResultItem resultItem = task.CreateResultItem(); + resultItem.TaskParameter = "OutputFile"; + resultItem.ItemName = "Compile"; + task.AppendResultItem(resultItem); + } targ.AppendTask(task); } { MSBuildTask task = targ.CreateTask(); // '$(SignAssembly)' == 'false' task.Name = "AssemblyInfo"; + task.AddParameter("CodeLanguage", "CS"); + task.Condition = "'$(SignAssembly)' != 'true'"; task.AddParameter("InternalsVisibleTo", assemblyName); task.AddParameter("OutputFile", "$(IntermediateOutputPath)" + assemblyName + ".IVT.Generated.cs"); + { + MSBuildTaskResultItem resultItem = task.CreateResultItem(); + resultItem.TaskParameter = "OutputFile"; + resultItem.ItemName = "Compile"; + task.AppendResultItem(resultItem); + } targ.AppendTask(task); } + uo.EnsureTargetExists("BeforeBuild"); uo.InsertTarget(targ); + uo.AddDependOnTarget("BeforeBuild", targ.Name); } + } diff --git a/mpt-core/AssemblyName/PublicKeyUtils.cs b/mpt-core/AssemblyName/PublicKeyUtils.cs index ad2c9ae..a05dd82 100644 --- a/mpt-core/AssemblyName/PublicKeyUtils.cs +++ b/mpt-core/AssemblyName/PublicKeyUtils.cs @@ -29,7 +29,7 @@ public static string GetPublicKeyStringFromContainer(string AssemblyKeyContainer { byte[] publicKey2 = GetPublicKey(AssemblyKeyContainerName); string output2 = ByteArrayToString(publicKey2); - return ", PublicKey=" + output2; + return output2; } public static string GetPublicKeyStringFromFilename(string AssemblyOriginatorKeyFile) @@ -37,6 +37,6 @@ public static string GetPublicKeyStringFromFilename(string AssemblyOriginatorKey byte[] snk = File.ReadAllBytes(AssemblyOriginatorKeyFile); byte[] publicKey1 = GetPublicKey(snk); string output1 = ByteArrayToString(publicKey1); - return ", PublicKey=" + output1; + return output1; } } diff --git a/mpt-csproj/Program.cs b/mpt-csproj/Program.cs index 36449f2..c282a0b 100644 --- a/mpt-csproj/Program.cs +++ b/mpt-csproj/Program.cs @@ -21,7 +21,7 @@ public static int Main(string[] args) { try { - return MainProcessing(args); + return (int)MainProcessing(args); } catch (Exception ex) { @@ -39,7 +39,7 @@ public static int Main(string[] args) } return (int)ExitCode.Exception; } - public static int MainProcessing(string[] args) + static ExitCode MainProcessing(string[] args) { var verbose = (string)null; var remove_warnings_as_errors = (string)null; @@ -131,7 +131,7 @@ public static int MainProcessing(string[] args) if (!bFile && !bDir) { Console.WriteLine($"unknown parameter {strUnparsedParameter}"); - Environment.Exit((int)ExitCode.WrongUsage); + return ExitCode.WrongUsage; } } if (String.IsNullOrWhiteSpace(dir) == false) @@ -154,7 +154,7 @@ public static int MainProcessing(string[] args) } if (listOfCsproj.Count == 0) { - return (int)ExitCode.NoInputFileSpecified; + return ExitCode.NoInputFileSpecified; } if (list_outputs != null) { @@ -279,6 +279,10 @@ public static int MainProcessing(string[] args) } if (friend_assembly_name != null) { + if (String.IsNullOrWhiteSpace(AssemblyOriginatorKeyFile) && String.IsNullOrWhiteSpace(AssemblyKeyContainerName)) + { + return ExitCode.WrongUsage; + } Console.WriteLine($"Injecting version property {version_string}"); foreach (var csproj_file in listOfCsproj) { @@ -295,11 +299,11 @@ public static int MainProcessing(string[] args) { publicKey = PublicKeyUtils.GetPublicKeyStringFromContainer(AssemblyKeyContainerName); } - file.InjectInternalsVisibleTo(import_name, publicKey); + file.InjectInternalsVisibleTo(friend_assembly_name, publicKey); } } } - return (int)ExitCode.Success; + return ExitCode.Success; } public static void ShowVersion() { diff --git a/mpt-csproj/mpt-csproj.csproj b/mpt-csproj/mpt-csproj.csproj index 5643798..2bc6745 100644 --- a/mpt-csproj/mpt-csproj.csproj +++ b/mpt-csproj/mpt-csproj.csproj @@ -35,7 +35,7 @@ - +