├── .gitattributes ├── .github └── workflows │ ├── git-releases.yml │ └── msbuild.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── Sample └── BasicSample │ ├── App.config │ ├── BasicSample.csproj │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Test.cs │ ├── Test.partial.cs │ ├── Test.xml │ └── Test.xslt ├── SeongTaeJeong.snk.gpg ├── XmlCodeGenerator.sln ├── XmlCodeGenerator ├── CHANGELOG.md ├── GlobalSuppressions.cs ├── Guids.cs ├── Properties │ └── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Resources │ └── Package.ico ├── Utils │ └── PathExtension.cs ├── VSPackage.resx ├── XmlCodeGenerator.cs ├── XmlCodeGenerator.csproj ├── XmlCodeGeneratorPackage.cs ├── app.config ├── overview.md ├── publishManifest.json ├── source.extension.vsixmanifest └── xml_xslt.png ├── XmlSrcGenerator ├── SourceGenerator.cs ├── XmlSrcGenerator.csproj ├── XmlSrcGenerator.nuspec └── deploy_nuget.bat ├── getNugetVersion.ps1 ├── introduce.txt ├── lib ├── Microsoft.VisualStudio.Interop.dll ├── Microsoft.VisualStudio.OLE.Interop.dll ├── Microsoft.VisualStudio.Shell.15.0.dll ├── Microsoft.VisualStudio.Shell.Framework.dll ├── Microsoft.VisualStudio.TextTemplating.VSHost.dll └── Microsoft.VisualStudio.Utilities.dll └── readFile.ps1 /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/git-releases.yml: -------------------------------------------------------------------------------- 1 | name: Create Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | env: 9 | # Path to the solution file relative to the root of the project. 10 | SOLUTION_FILE_PATH: . 11 | 12 | # Configuration type to build. 13 | # You can convert this to a build matrix if you need coverage of multiple configuration types. 14 | # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 15 | BUILD_CONFIGURATION: Release 16 | 17 | jobs: 18 | create_release: 19 | name: Create release 20 | runs-on: ubuntu-latest 21 | outputs: 22 | upload_url: ${{ steps.create_release.outputs.upload_url }} 23 | steps: 24 | - name: Get version from tag 25 | id: tag_name 26 | run: | 27 | echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v} 28 | shell: bash 29 | 30 | - name: Checkout code 31 | uses: actions/checkout@v2 32 | 33 | - name: Get Changelog Entry 34 | id: changelog_reader 35 | uses: mindsers/changelog-reader-action@v2 36 | with: 37 | version: ${{ steps.tag_name.outputs.current_version }} 38 | path: ./XmlCodeGenerator/CHANGELOG.md 39 | 40 | - name: Create Release 41 | id: create_release 42 | uses: actions/create-release@latest 43 | env: 44 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 45 | with: 46 | tag_name: ${{ github.ref }} 47 | release_name: ${{env.BUILD_CONFIGURATION}} ${{ github.ref }} 48 | body: ${{ steps.changelog_reader.outputs.changes }} 49 | draft: false 50 | prerelease: false 51 | 52 | build: 53 | runs-on: windows-2022 54 | needs: create_release 55 | 56 | steps: 57 | - uses: actions/checkout@v2 58 | - name: Decrypt snk 59 | run: gpg --quiet --batch --yes --decrypt --passphrase="${{ secrets.SNKFILE_DEC_KEY }}" --output ../SeongTaeJeong.snk ./SeongTaeJeong.snk.gpg 60 | 61 | - name: Add MSBuild to PATH 62 | uses: microsoft/setup-msbuild@v1 63 | 64 | - name: Restore NuGet packages 65 | working-directory: ${{env.GITHUB_WORKSPACE}} 66 | run: nuget restore ${{env.SOLUTION_FILE_PATH}} 67 | 68 | - name: Build 69 | working-directory: ${{env.GITHUB_WORKSPACE}} 70 | # Add additional options to the MSBuild command line here (like platform or verbosity level). 71 | # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference 72 | run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} 73 | 74 | - name: Publish extension to Marketplace 75 | uses: cezarypiatek/VsixPublisherAction@0.2 76 | with: 77 | extension-file: ./XmlCodeGenerator/bin/${{env.BUILD_CONFIGURATION}}/XmlCodeGenerator.vsix 78 | publish-manifest-file: ./XmlCodeGenerator/publishManifest.json 79 | personal-access-code: ${{ secrets.VSGALLERY_API_KEY }} 80 | 81 | - name: Publish NuGet 82 | id: pub_nuget 83 | uses: brandedoutcast/publish-nuget@v2.5.5 84 | with: 85 | PROJECT_FILE_PATH: ./XmlSrcGenerator/XmlSrcGenerator.csproj 86 | NUGET_KEY: ${{secrets.NUGET_API_KEY}} 87 | TAG_COMMIT: false 88 | INCLUDE_SYMBOLS: true 89 | 90 | - name: Upload VSIX Release Asset 91 | id: upload-vsix-release-asset 92 | uses: actions/upload-release-asset@v1 93 | env: 94 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 95 | with: 96 | upload_url: ${{ needs.create_release.outputs.upload_url }} 97 | asset_path: ./XmlCodeGenerator/bin/${{env.BUILD_CONFIGURATION}}/XmlCodeGenerator.vsix 98 | asset_name: XmlCodeGenerator.vsix 99 | asset_content_type: application/octet-stream 100 | 101 | - name: Upload Nuget Release Asset 102 | if: steps.pub_nuget.outputs.PACKAGE_PATH != '' 103 | id: upload-nuget-release-asset 104 | uses: actions/upload-release-asset@v1 105 | env: 106 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 107 | with: 108 | upload_url: ${{ needs.create_release.outputs.upload_url }} 109 | asset_path: ${{ steps.pub_nuget.outputs.PACKAGE_PATH }} 110 | asset_name: ${{ steps.pub_nuget.outputs.PACKAGE_NAME }} 111 | asset_content_type: application/octet-stream 112 | -------------------------------------------------------------------------------- /.github/workflows/msbuild.yml: -------------------------------------------------------------------------------- 1 | name: MSBuild 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags-ignore: 8 | - 'v*' 9 | pull_request: 10 | branches: 11 | - master 12 | tags-ignore: 13 | - 'v*' 14 | 15 | env: 16 | # Path to the solution file relative to the root of the project. 17 | SOLUTION_FILE_PATH: . 18 | 19 | # Configuration type to build. 20 | # You can convert this to a build matrix if you need coverage of multiple configuration types. 21 | # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 22 | BUILD_CONFIGURATION: Release 23 | 24 | jobs: 25 | 26 | build: 27 | runs-on: windows-2022 28 | 29 | steps: 30 | - uses: actions/checkout@v2 31 | - name: Decrypt snk 32 | run: gpg --quiet --batch --yes --decrypt --passphrase="${{ secrets.SNKFILE_DEC_KEY }}" --output ../SeongTaeJeong.snk ./SeongTaeJeong.snk.gpg 33 | 34 | - name: Add MSBuild to PATH 35 | uses: microsoft/setup-msbuild@v1 36 | 37 | - name: Restore NuGet packages 38 | working-directory: ${{env.GITHUB_WORKSPACE}} 39 | run: nuget restore ${{env.SOLUTION_FILE_PATH}} 40 | 41 | - name: Build 42 | working-directory: ${{env.GITHUB_WORKSPACE}} 43 | # Add additional options to the MSBuild command line here (like platform or verbosity level). 44 | # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference 45 | run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | /XmlSrcGenerator/nuget/root 244 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | XmlCodeGenerator (C) 2013 SeongTae Jeong 2 | This source is subject to the Microsoft Public License (Ms-PL) 3 | 4 | Microsoft Public License (Ms-PL) 5 | 6 | This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software. 7 | 8 | 1. Definitions 9 | The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. A "contribution" is the original software, or any additions or changes to the software. A "contributor" is any person that distributes its contribution under this license. "Licensed patents" are a contributor's patent claims that read directly on its contribution. 10 | 11 | 2. Grant of Rights 12 | (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. 13 | (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. 14 | 15 | 3. Conditions and Limitations 16 | (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. 17 | (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. 18 | (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. 19 | (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. 20 | (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![MSBuild](https://github.com/stjeong/XmlCodeGenerator/workflows/MSBuild/badge.svg) 2 | ![GitHub](https://img.shields.io/badge/license-Ms--PL-lightgrey) 3 | ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/stjeong/XmlCodeGenerator) 4 | 5 | What is it? 6 | ================================ 7 | 8 | Visual Studio 2012/2013/2015/2017/2019 plugin: Generates source codes with XML + XSLT(includes pre-defined XSLT) 9 | 10 | 11 | Download 12 | ================================ 13 | This extension is registered in Visual Studio Gallery. So you can download and install in Visual Studio Extension Manager. 14 | 15 | XmlCodeGenerator: http://visualstudiogallery.msdn.microsoft.com/20163975-c675-4f1c-986f-d2489136469d 16 | 17 | 18 | License 19 | ================================ 20 | Microsoft Public License (Ms-PL) 21 | 22 | (Refer to LICENSE.txt) -------------------------------------------------------------------------------- /Sample/BasicSample/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Sample/BasicSample/BasicSample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5CE76AC7-3DBF-459D-A4B0-B495406F6CB2} 8 | Exe 9 | Properties 10 | BasicSample 11 | BasicSample 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | True 50 | True 51 | Test.xml 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | XmlCodeGenerator 61 | Test.cs 62 | 63 | 64 | 65 | 66 | 73 | -------------------------------------------------------------------------------- /Sample/BasicSample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace BasicSample 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | macroTest.Test test = new macroTest.Test(); 15 | test.DoTest(5); 16 | 17 | //XmlCodeGenerator gen = new XmlCodeGenerator(); 18 | 19 | //string xmlFile = Path.Combine(Environment.CurrentDirectory, "Test.xml"); 20 | //string text = gen.GenerateCode(xmlFile); 21 | 22 | //Console.WriteLine(text); 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sample/BasicSample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BasicSample")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BasicSample")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("5ce76ac7-3dbf-459d-a4b0-b495406f6cb2")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Sample/BasicSample/Test.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace macroTest 7 | { 8 | public partial class Test 9 | { 10 | private void DoIt(int condition) 11 | { 12 | 13 | if (condition == 1) 14 | { 15 | funcName_1(); 16 | } 17 | 18 | if (condition == 2) 19 | { 20 | funcName_2(); 21 | } 22 | 23 | if (condition == 3) 24 | { 25 | funcName_3(); 26 | } 27 | 28 | if (condition == 4) 29 | { 30 | funcName_4(); 31 | } 32 | 33 | if (condition == 5) 34 | { 35 | funcName_5(); 36 | } 37 | 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sample/BasicSample/Test.partial.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace macroTest 8 | { 9 | public partial class Test 10 | { 11 | public void DoTest(int condition) 12 | { 13 | // DoIt(condition); 14 | } 15 | 16 | void funcName_1() 17 | { 18 | Console.WriteLine("funcName_1"); 19 | } 20 | 21 | void funcName_2() 22 | { 23 | Console.WriteLine("funcName_2"); 24 | } 25 | 26 | void funcName_3() 27 | { 28 | Console.WriteLine("funcName_3"); 29 | } 30 | 31 | void funcName_4() 32 | { 33 | Console.WriteLine("funcName_4"); 34 | } 35 | 36 | void funcName_5() 37 | { 38 | Console.WriteLine("funcName_5"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sample/BasicSample/Test.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Sample/BasicSample/Test.xslt: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 20 | 21 | 27 | -------------------------------------------------------------------------------- /SeongTaeJeong.snk.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stjeong/XmlCodeGenerator/7353271fdf315ef5b7d9c17bd96318ce8800c599/SeongTaeJeong.snk.gpg -------------------------------------------------------------------------------- /XmlCodeGenerator.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31912.275 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F5CA69FE-6A86-4EB4-9909-047EA1988DE4}" 7 | ProjectSection(SolutionItems) = preProject 8 | getNugetVersion.ps1 = getNugetVersion.ps1 9 | introduce.txt = introduce.txt 10 | LICENSE.txt = LICENSE.txt 11 | readFile.ps1 = readFile.ps1 12 | README.md = README.md 13 | EndProjectSection 14 | EndProject 15 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample", "Sample", "{C6A0F6E1-0C61-4D8B-97D9-ED4175B839C5}" 16 | EndProject 17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlCodeGenerator", "XmlCodeGenerator\XmlCodeGenerator.csproj", "{622F3DB9-67C7-4E31-86CD-F4C2F3865E3D}" 18 | EndProject 19 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicSample", "Sample\BasicSample\BasicSample.csproj", "{5CE76AC7-3DBF-459D-A4B0-B495406F6CB2}" 20 | EndProject 21 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lib", "lib", "{035CE61F-2E61-4D31-AB17-D112F104A385}" 22 | ProjectSection(SolutionItems) = preProject 23 | lib\Microsoft.VisualStudio.Interop.dll = lib\Microsoft.VisualStudio.Interop.dll 24 | lib\Microsoft.VisualStudio.OLE.Interop.dll = lib\Microsoft.VisualStudio.OLE.Interop.dll 25 | lib\Microsoft.VisualStudio.Shell.15.0.dll = lib\Microsoft.VisualStudio.Shell.15.0.dll 26 | lib\Microsoft.VisualStudio.Shell.Framework.dll = lib\Microsoft.VisualStudio.Shell.Framework.dll 27 | lib\Microsoft.VisualStudio.TextTemplating.VSHost.dll = lib\Microsoft.VisualStudio.TextTemplating.VSHost.dll 28 | lib\Microsoft.VisualStudio.Utilities.dll = lib\Microsoft.VisualStudio.Utilities.dll 29 | EndProjectSection 30 | EndProject 31 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XmlSrcGenerator", "XmlSrcGenerator\XmlSrcGenerator.csproj", "{EBDC7EC1-98F0-4E58-B97A-3EBCE9CBF42B}" 32 | EndProject 33 | Global 34 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 35 | Debug|Any CPU = Debug|Any CPU 36 | Release|Any CPU = Release|Any CPU 37 | EndGlobalSection 38 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 39 | {622F3DB9-67C7-4E31-86CD-F4C2F3865E3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {622F3DB9-67C7-4E31-86CD-F4C2F3865E3D}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {622F3DB9-67C7-4E31-86CD-F4C2F3865E3D}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {622F3DB9-67C7-4E31-86CD-F4C2F3865E3D}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {5CE76AC7-3DBF-459D-A4B0-B495406F6CB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {5CE76AC7-3DBF-459D-A4B0-B495406F6CB2}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {5CE76AC7-3DBF-459D-A4B0-B495406F6CB2}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {5CE76AC7-3DBF-459D-A4B0-B495406F6CB2}.Release|Any CPU.Build.0 = Release|Any CPU 47 | {EBDC7EC1-98F0-4E58-B97A-3EBCE9CBF42B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 48 | {EBDC7EC1-98F0-4E58-B97A-3EBCE9CBF42B}.Debug|Any CPU.Build.0 = Debug|Any CPU 49 | {EBDC7EC1-98F0-4E58-B97A-3EBCE9CBF42B}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {EBDC7EC1-98F0-4E58-B97A-3EBCE9CBF42B}.Release|Any CPU.Build.0 = Release|Any CPU 51 | EndGlobalSection 52 | GlobalSection(SolutionProperties) = preSolution 53 | HideSolutionNode = FALSE 54 | EndGlobalSection 55 | GlobalSection(NestedProjects) = preSolution 56 | {5CE76AC7-3DBF-459D-A4B0-B495406F6CB2} = {C6A0F6E1-0C61-4D8B-97D9-ED4175B839C5} 57 | EndGlobalSection 58 | GlobalSection(ExtensibilityGlobals) = postSolution 59 | SolutionGuid = {E62A0BFD-1E40-48A5-A2F5-519FED6A656E} 60 | EndGlobalSection 61 | GlobalSection(CodealikeProperties) = postSolution 62 | SolutionGuid = 24cb72a6-a712-44f9-aeca-ba49f77b2904 63 | EndGlobalSection 64 | EndGlobal 65 | -------------------------------------------------------------------------------- /XmlCodeGenerator/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [1.3.1] - 2021-03-03 8 | 9 | ### Added 10 | - CHANGELOG.md 11 | 12 | ## [1.3] - 2020-06-13 13 | 14 | ### Changed 15 | 16 | - Add support for Visual Studio 2019 17 | 18 | ## [1.2] - 2017-04-26 19 | 20 | ### Changed 21 | 22 | - Add support for Visual Studio 2017 23 | 24 | ## [1.1] - 2015-07-08 25 | 26 | ### Changed 27 | 28 | - Add support for Visual Studio 2015 29 | 30 | ## [1.0] - 2013-10-31 31 | 32 | ### Added 33 | 34 | - Initial checked-in (For Koreans, read [this article](http://www.sysnet.pe.kr/2/0/11809)) 35 | -------------------------------------------------------------------------------- /XmlCodeGenerator/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. Project-level 3 | // suppressions either have no target or are given a specific target 4 | // and scoped to a namespace, type, member, etc. 5 | // 6 | // To add a suppression to this file, right-click the message in the 7 | // Error List, point to "Suppress Message(s)", and click "In Project 8 | // Suppression File". You do not need to add suppressions to this 9 | // file manually. 10 | 11 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1017:MarkAssembliesWithComVisible")] 12 | -------------------------------------------------------------------------------- /XmlCodeGenerator/Guids.cs: -------------------------------------------------------------------------------- 1 | // Guids.cs 2 | // MUST match guids.h 3 | using System; 4 | 5 | namespace wwwsysnetpekr.XmlCodeGenerator 6 | { 7 | static class GuidList 8 | { 9 | public const string guidXmlCodeGeneratorPkgString = "b9a2f630-ec32-49a5-96a9-612bcb1d25e4"; 10 | public const string guidXmlCodeGeneratorCmdSetString = "d24cbf97-3f83-4ced-b342-8ae04b59f46e"; 11 | }; 12 | } -------------------------------------------------------------------------------- /XmlCodeGenerator/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Resources; 4 | using System.Runtime.CompilerServices; 5 | using System.Runtime.InteropServices; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("XmlCodeGenerator")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("www.sysnet.pe.kr")] 14 | [assembly: AssemblyProduct("XmlCodeGenerator")] 15 | [assembly: AssemblyCopyright("")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | [assembly: ComVisible(false)] 19 | [assembly: CLSCompliant(false)] 20 | [assembly: NeutralResourcesLanguage("en-US")] 21 | 22 | // Version information for an assembly consists of the following four values: 23 | // 24 | // Major Version 25 | // Minor Version 26 | // Build Number 27 | // Revision 28 | // 29 | // You can specify all the values or you can default the Revision and Build Numbers 30 | // by using the '*' as shown below: 31 | 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /XmlCodeGenerator/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace wwwsysnetpekr.XmlCodeGenerator { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("wwwsysnetpekr.XmlCodeGenerator.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /XmlCodeGenerator/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 11 | 12 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | text/microsoft-resx 119 | 120 | 121 | 2.0 122 | 123 | 124 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 125 | 126 | 127 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 128 | 129 | -------------------------------------------------------------------------------- /XmlCodeGenerator/Resources/Package.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stjeong/XmlCodeGenerator/7353271fdf315ef5b7d9c17bd96318ce8800c599/XmlCodeGenerator/Resources/Package.ico -------------------------------------------------------------------------------- /XmlCodeGenerator/Utils/PathExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | using System.Globalization; 7 | 8 | namespace BclExtension 9 | { 10 | /// 11 | /// 경로와 관련된 유틸리티 함수 모음 12 | /// 13 | public static class PathExtension 14 | { 15 | /// 16 | /// 일반 경로를 UNC 형식의 경로로 반환 17 | /// 18 | /// IP 또는 컴퓨터 이름 19 | /// 절대 경로 20 | /// UNC 포맷 경로 21 | public static string ConvertToUNCPath(string ipAddress, string path) 22 | { 23 | if (Path.IsPathRooted(path) == false) 24 | { 25 | if (path != null && path.Length == 1) 26 | { 27 | return string.Format(CultureInfo.CurrentCulture, @"\\{0}\{1}$", ipAddress, path); 28 | } 29 | 30 | return string.Empty; 31 | } 32 | 33 | string fileName = Path.GetFileName(path); 34 | string driveLetter = Path.GetPathRoot(path); 35 | string folder = Path.GetDirectoryName(path); 36 | 37 | if (folder != null && folder.Length >= 3) 38 | { 39 | folder = folder.Substring(3); 40 | } 41 | 42 | string uncPath = string.Format(CultureInfo.CurrentCulture, @"\\{0}\{1}$\{2}", 43 | ipAddress, driveLetter.Substring(0, 1), folder); 44 | 45 | return Path.Combine(uncPath, fileName).TrimEnd(Path.DirectorySeparatorChar); 46 | } 47 | 48 | /// 49 | /// 명령행 인자를 가지고 있는 경로에서 파일명을 반환 50 | /// 51 | /// 경로 52 | /// 파일명 53 | public static string GetFileNameFromIncludingInvalidChars(string path) 54 | { 55 | char[] invalidChars = Path.GetInvalidPathChars(); 56 | foreach (char ch in invalidChars) 57 | { 58 | path = path.Replace(ch, ' '); 59 | } 60 | 61 | string converted = Path.GetFileName(path); 62 | return converted.Split(' ')[0]; 63 | } 64 | 65 | /// 66 | /// 경로명에서 파일명을 바꿔준다. 67 | /// 68 | /// 파일 경로 69 | /// 새로운 파일명 70 | /// 파일명이 교체된 경로 71 | public static string ChangeFileName(string path, string newFileName) 72 | { 73 | string parent = Path.GetDirectoryName(path); 74 | return Path.Combine(parent, newFileName); 75 | } 76 | 77 | /// 78 | /// 경로에서 drive 문자를 반환 79 | /// 80 | /// 81 | /// 82 | public static char GetDriveLetter(string path) 83 | { 84 | return path[0]; 85 | } 86 | 87 | /// 88 | /// URL 을 연결해서 반환 89 | /// 90 | /// URL 폴더 91 | /// 파일명 92 | /// 93 | public static Uri UrlCombine(string baseUri, string fileName) 94 | { 95 | if (baseUri.EndsWith("/") == false) 96 | { 97 | baseUri += "/"; 98 | } 99 | 100 | Uri uri = new Uri(baseUri); 101 | Uri sourceUri = new Uri(uri, fileName); 102 | 103 | return sourceUri; 104 | } 105 | 106 | /// 107 | /// Shell 의 open 명령 실행 108 | /// 109 | /// 폴더 경로 110 | public static void OpenVerb(string path) 111 | { 112 | System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("iexplore.exe"); 113 | startInfo.Arguments = path; 114 | System.Diagnostics.Process.Start(startInfo); 115 | } 116 | 117 | /// 118 | /// 파일명에 따라 부모 폴더를 검색해 가면서 파일이 있는 경우에만 경로를 반환 119 | /// 120 | /// 검색 시작 경로 및 파일명 121 | /// 검색된 파일명 122 | public static string SearchInParents(string path) 123 | { 124 | if (File.Exists(path) == true) 125 | { 126 | return path; 127 | } 128 | 129 | string folder = Path.GetDirectoryName(path); 130 | string fileName = Path.GetFileName(path); 131 | 132 | 133 | while (true) 134 | { 135 | DirectoryInfo dir = Directory.GetParent(folder); 136 | if (dir == null) 137 | { 138 | break; 139 | } 140 | 141 | string filePath = Path.Combine(dir.FullName, fileName); 142 | if (File.Exists(filePath) == true) 143 | { 144 | return filePath; 145 | } 146 | 147 | folder = dir.FullName; 148 | } 149 | 150 | return string.Empty; 151 | } 152 | 153 | } 154 | } 155 | 156 | -------------------------------------------------------------------------------- /XmlCodeGenerator/VSPackage.resx: -------------------------------------------------------------------------------- 1 |  2 | 12 | 13 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | text/microsoft-resx 120 | 121 | 122 | 2.0 123 | 124 | 125 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 126 | 127 | 128 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 129 | 130 | 131 | 132 | XmlCodeGenerator 133 | 134 | 135 | Generates source code with XML + XSLT (includes pre-defined XSLT) 136 | 137 | 138 | Resources\Package.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 139 | 140 | -------------------------------------------------------------------------------- /XmlCodeGenerator/XmlCodeGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using System.IO; 4 | using System.Runtime.InteropServices; 5 | using System.Xml.Xsl; 6 | using System.Diagnostics; 7 | 8 | using System.Collections; 9 | using Microsoft.Win32; 10 | using System.Globalization; 11 | using System.Reflection; 12 | using System.Runtime.Remoting; 13 | using System.Text; 14 | using System.Xml; 15 | using System.Collections.Generic; 16 | using Microsoft.VisualStudio.Shell; 17 | using System.CodeDom.Compiler; 18 | using Microsoft.VisualStudio.Shell.Interop; 19 | using Microsoft.VisualStudio.Designer.Interfaces; 20 | using Microsoft.VisualStudio.TextTemplating.VSHost; 21 | 22 | [Guid("0FECB64A-8779-4A7B-B7CD-226DD6531FB1")] 23 | public abstract class vsContextGuids 24 | { 25 | [MarshalAs(UnmanagedType.LPStr)] 26 | public const string vsContextGuidVCSProject = "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}"; 27 | [MarshalAs(UnmanagedType.LPStr)] 28 | public const string vsContextGuidVCSEditor = "{694DD9B6-B865-4C5B-AD85-86356E9C88DC}"; 29 | [MarshalAs(UnmanagedType.LPStr)] 30 | public const string vsContextGuidVBProject = "{164B10B9-B200-11D0-8C61-00A0C91E29D5}"; 31 | [MarshalAs(UnmanagedType.LPStr)] 32 | public const string vsContextGuidVBEditor = "{E34ACDC0-BAAE-11D0-88BF-00A0C9110049}"; 33 | [MarshalAs(UnmanagedType.LPStr)] 34 | public const string vsContextGuidVJSProject = "{E6FDF8B0-F3D1-11D4-8576-0002A516ECE8}"; 35 | [MarshalAs(UnmanagedType.LPStr)] 36 | public const string vsContextGuidVJSEditor = "{E6FDF88A-F3D1-11D4-8576-0002A516ECE8}"; 37 | } 38 | 39 | namespace BclExtension 40 | { 41 | /// 42 | /// This class exists to be cocreated a in a preprocessor build step. 43 | /// 44 | [Guid(XmlCodeGenerator.RefGuid)] 45 | [ClassInterface(ClassInterfaceType.None)] 46 | [CodeGeneratorRegistration(typeof(XmlCodeGenerator), "C# XML Code Generator", vsContextGuids.vsContextGuidVCSProject, GeneratesDesignTimeSource = true)] 47 | [CodeGeneratorRegistration(typeof(XmlCodeGenerator), "VB XML Code Generator", vsContextGuids.vsContextGuidVBProject, GeneratesDesignTimeSource = true)] 48 | [ProvideObject(typeof(XmlCodeGenerator))] 49 | public class XmlCodeGenerator : BaseCodeGeneratorWithSite 50 | { 51 | internal const string RefGuid = "64B3B9EF-EEF7-4523-82FD-7D68459D7DFA"; 52 | internal const string DefaultXslFileName = "default.xslt"; 53 | 54 | internal string BaseFolder 55 | { 56 | get 57 | { 58 | string modulePath = typeof(XmlCodeGenerator).Assembly.Location; 59 | return Path.GetDirectoryName(modulePath); 60 | } 61 | } 62 | 63 | /// 64 | /// 기본 생성자 65 | /// 66 | public XmlCodeGenerator() 67 | { 68 | } 69 | 70 | static Dictionary xsltDict = new Dictionary(); 71 | 72 | /// 73 | /// public method for GenerateCode 74 | /// 75 | /// 76 | /// 77 | public string GenerateCode(string inputFileName) 78 | { 79 | return Encoding.UTF8.GetString(GenerateCode(inputFileName, string.Empty)); 80 | } 81 | 82 | /// 83 | /// demand-creates a CodeDomProvider 84 | /// 85 | protected override byte[] GenerateCode(string inputFileName, string inputFileContent) 86 | { 87 | string xmlFilePath = inputFileName; 88 | string xslFilePath = ResolveXSLPath(xmlFilePath); 89 | if (string.IsNullOrEmpty(xslFilePath) == true) 90 | { 91 | string msg = string.Format("// XSL File not found ({0})", xslFilePath); 92 | return System.Text.Encoding.UTF8.GetBytes(msg); 93 | } 94 | 95 | Debug.WriteLine("Original XmlFilePath: " + xmlFilePath); 96 | xmlFilePath = ResolveXmlPath(xmlFilePath); 97 | Debug.WriteLine("Resolved XmlFilePath: " + xmlFilePath); 98 | Debug.WriteLine("Resolved XslFilePath: " + xslFilePath); 99 | 100 | #if DEBUG 101 | string txt2 = File.ReadAllText(xslFilePath); 102 | #endif 103 | 104 | XslCompiledTransform xslt; 105 | XsltSettings xst = XsltSettings.Default; 106 | xst.EnableScript = true; 107 | 108 | try 109 | { 110 | string xsltText = File.ReadAllText(xslFilePath); 111 | 112 | // 재활용한다. 113 | if (xsltDict.TryGetValue(xsltText, out xslt) == false) 114 | { 115 | xslt = new XslCompiledTransform(); 116 | 117 | StringReader sr = new StringReader(xsltText); 118 | using (XmlReader xr = XmlReader.Create(sr)) 119 | { 120 | xslt.Load(xr, xst, null); 121 | } 122 | 123 | xsltDict.Add(xsltText, xslt); 124 | } 125 | } 126 | catch (Exception ex) 127 | { 128 | string output = string.Format("{0}{1}{2}", ex.Message, Environment.NewLine, ex.ToString()); 129 | return System.Text.Encoding.UTF8.GetBytes(output); 130 | } 131 | 132 | StringBuilder sb = new StringBuilder(); 133 | using (StringWriter sw = new StringWriter(sb, CultureInfo.CurrentCulture)) 134 | { 135 | XmlWriterSettings xws = new XmlWriterSettings(); 136 | xws.ConformanceLevel = ConformanceLevel.Auto; 137 | xws.Encoding = Encoding.UTF8; 138 | 139 | XmlReaderSettings xrs = new XmlReaderSettings(); 140 | 141 | XmlWriter writer = XmlTextWriter.Create(sw, xws); 142 | using (XmlReader reader = XmlReader.Create(xmlFilePath, xrs)) 143 | { 144 | XsltArgumentList xal = new XsltArgumentList(); 145 | // LoadXsltExtensionMethod(xal); 146 | xal.AddParam("XCG_CurrentTime", string.Empty, DateTime.Now.ToString(CultureInfo.InvariantCulture)); 147 | xal.AddParam("XCG_Namespace", string.Empty, this.FileNamespace); 148 | xal.AddParam("XCG_BaseFolder", string.Empty, this.BaseFolder); 149 | xal.AddParam("XCG_Version", string.Empty, "1.0"); 150 | xslt.Transform(reader, xal, writer); 151 | } 152 | 153 | #if DEBUG 154 | string txt = sb.ToString(); 155 | #endif 156 | } 157 | 158 | return System.Text.Encoding.UTF8.GetBytes(sb.ToString()); 159 | } 160 | 161 | /// 162 | /// XML 파일 경로가 XML 파일안에 있는 경우를 해석 163 | /// 164 | /// VS.NET IDE 에서 제공되는 XML 파일 경로 165 | /// 166 | private static string ResolveXmlPath(string xmlFilePath) 167 | { 168 | XmlDocument xmlDoc = new XmlDocument(); 169 | xmlDoc.Load(xmlFilePath); 170 | 171 | string baseFolder = Path.GetDirectoryName(xmlFilePath); 172 | 173 | XmlNode sourceNode = xmlDoc.SelectSingleNode("//ExternalSource"); 174 | if (sourceNode == null) 175 | { 176 | return xmlFilePath; 177 | } 178 | 179 | return Path.Combine(baseFolder, sourceNode.InnerText); 180 | } 181 | 182 | private string ResolveXSLPath(string xmlFilePath) 183 | { 184 | // 0: 만약 XML 파일안에 xcg-xsltKey Preprocessor 가 있다면 그를 따른다. 185 | XmlDocument document = new XmlDocument(); 186 | document.Load(xmlFilePath); 187 | XmlProcessingInstruction xcgPI = 188 | document.SelectSingleNode("/processing-instruction(\"xcg-xsltKey\")") 189 | as XmlProcessingInstruction; 190 | 191 | if (xcgPI != null) 192 | { 193 | return Path.Combine(this.BaseFolder, xcgPI.Value) + ".xslt"; 194 | } 195 | 196 | // 0.1: 만약 XML 파일안에 xcg-xsltFileName Preprocessor 가 있다면 그를 따른다. 197 | xcgPI = document.SelectSingleNode("/processing-instruction(\"xcg-xsltFileName\")") as XmlProcessingInstruction; 198 | 199 | if (xcgPI != null) 200 | { 201 | string xmlFolder = Path.GetDirectoryName(xmlFilePath); 202 | return Path.Combine(xmlFolder, xcgPI.Value) + ".xslt"; 203 | } 204 | 205 | // 1: XML 파일에서 "xslt" 확장자만 교체해서 검색 206 | string xslFilePath = Path.ChangeExtension(xmlFilePath, "xslt"); 207 | if (File.Exists(xslFilePath) == true) 208 | { 209 | return xslFilePath; 210 | } 211 | 212 | // 2: 같은 폴더에서 파일명만 default.xslt 213 | string defaultXslFilePath = PathExtension.ChangeFileName(xslFilePath, DefaultXslFileName); 214 | if (File.Exists(defaultXslFilePath) == true) 215 | { 216 | return defaultXslFilePath; 217 | } 218 | 219 | // 3: 상위 폴더에서 루트 드라이브까지 파일명이 XML 파일에서 xslt 확장자만 교체한 것과 일치한 것을 검색 220 | string found = PathExtension.SearchInParents(xslFilePath); 221 | if (string.IsNullOrEmpty(found) == false) 222 | { 223 | return found; 224 | } 225 | 226 | // 4: 상위 폴더에서 루트 드라이브까지 파일명이 default.xslt 파일이 있는지 검사. 227 | return PathExtension.SearchInParents(defaultXslFilePath); 228 | } 229 | 230 | public override string GetDefaultExtension() 231 | { 232 | CodeDomProvider codeDom = GetCodeProvider(); 233 | Debug.Assert(codeDom != null, "CodeDomProvider is NULL."); 234 | string extension = codeDom.FileExtension; 235 | if (extension != null && extension.Length > 0) 236 | { 237 | extension = "." + extension.TrimStart(".".ToCharArray()); 238 | } 239 | return extension; 240 | } 241 | 242 | private CodeDomProvider codeDomProvider = null; 243 | protected virtual CodeDomProvider GetCodeProvider() 244 | { 245 | if (codeDomProvider == null) 246 | { 247 | // Query for IVSMDCodeDomProvider/SVSMDCodeDomProvider for this project type 248 | IVSMDCodeDomProvider provider = GetService(typeof(SVSMDCodeDomProvider)) 249 | as IVSMDCodeDomProvider; 250 | 251 | if (provider != null) 252 | { 253 | codeDomProvider = provider.CodeDomProvider as CodeDomProvider; 254 | } 255 | else 256 | { 257 | //In the case where no language specific CodeDom is available, fall back to C# 258 | codeDomProvider = CodeDomProvider.CreateProvider("C#"); 259 | } 260 | } 261 | return codeDomProvider; 262 | } 263 | } 264 | } 265 | 266 | -------------------------------------------------------------------------------- /XmlCodeGenerator/XmlCodeGenerator.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 15.0 5 | 11.0 6 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 7 | 8 | 9 | 10 | 11 | 12 | 4.0 13 | publish\ 14 | true 15 | Disk 16 | false 17 | Foreground 18 | 7 19 | Days 20 | false 21 | false 22 | true 23 | 0 24 | 1.0.0.%2a 25 | false 26 | false 27 | true 28 | 29 | 30 | 31 | 32 | 33 | Debug 34 | AnyCPU 35 | 2.0 36 | {622F3DB9-67C7-4E31-86CD-F4C2F3865E3D} 37 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 38 | Library 39 | Properties 40 | wwwsysnetpekr.XmlCodeGenerator 41 | XmlCodeGenerator 42 | True 43 | ..\..\..\..\SeongTaeJeong.snk 44 | v4.8 45 | 46 | 47 | true 48 | full 49 | false 50 | bin\Debug\ 51 | DEBUG;TRACE 52 | prompt 53 | 4 54 | false 55 | 56 | 57 | pdbonly 58 | true 59 | bin\Release\ 60 | TRACE 61 | prompt 62 | 4 63 | false 64 | false 65 | MinimumRecommendedRules.ruleset 66 | true 67 | 68 | 69 | 70 | 71 | False 72 | ..\lib\Microsoft.VisualStudio.Interop.dll 73 | 74 | 75 | False 76 | ..\lib\Microsoft.VisualStudio.OLE.Interop.dll 77 | 78 | 79 | False 80 | ..\lib\Microsoft.VisualStudio.Shell.15.0.dll 81 | 82 | 83 | False 84 | ..\lib\Microsoft.VisualStudio.Shell.Framework.dll 85 | 86 | 87 | False 88 | ..\lib\Microsoft.VisualStudio.TextTemplating.VSHost.dll 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | True 103 | True 104 | Resources.resx 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | ResXFileCodeGenerator 115 | Resources.Designer.cs 116 | Designer 117 | 118 | 119 | true 120 | VSPackage 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | Designer 129 | 130 | 131 | 132 | 133 | 134 | Always 135 | true 136 | 137 | 138 | 139 | 140 | False 141 | .NET Framework 3.5 SP1 142 | false 143 | 144 | 145 | 146 | true 147 | 148 | 149 | 150 | 157 | -------------------------------------------------------------------------------- /XmlCodeGenerator/XmlCodeGeneratorPackage.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.Shell; 2 | using System; 3 | using System.Diagnostics; 4 | using System.Globalization; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace wwwsysnetpekr.XmlCodeGenerator 8 | { 9 | /// 10 | /// This is the class that implements the package exposed by this assembly. 11 | /// 12 | /// The minimum requirement for a class to be considered a valid package for Visual Studio 13 | /// is to implement the IVsPackage interface and register itself with the shell. 14 | /// This package uses the helper classes defined inside the Managed Package Framework (MPF) 15 | /// to do it: it derives from the Package class that provides the implementation of the 16 | /// IVsPackage interface and uses the registration attributes defined in the framework to 17 | /// register itself and its components with the shell. 18 | /// 19 | // This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is 20 | // a package. 21 | [PackageRegistration(UseManagedResourcesOnly = true)] 22 | // This attribute is used to register the information needed to show this package 23 | // in the Help/About dialog of Visual Studio. 24 | [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] 25 | [Guid(GuidList.guidXmlCodeGeneratorPkgString)] 26 | public sealed class XmlCodeGeneratorPackage : Package 27 | { 28 | /// 29 | /// Default constructor of the package. 30 | /// Inside this method you can place any initialization code that does not require 31 | /// any Visual Studio service because at this point the package object is created but 32 | /// not sited yet inside Visual Studio environment. The place to do all the other 33 | /// initialization is the Initialize method. 34 | /// 35 | public XmlCodeGeneratorPackage() 36 | { 37 | Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString())); 38 | } 39 | 40 | 41 | 42 | ///////////////////////////////////////////////////////////////////////////// 43 | // Overridden Package Implementation 44 | #region Package Members 45 | 46 | /// 47 | /// Initialization of the package; this method is called right after the package is sited, so this is the place 48 | /// where you can put all the initialization code that rely on services provided by VisualStudio. 49 | /// 50 | protected override void Initialize() 51 | { 52 | Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); 53 | base.Initialize(); 54 | 55 | } 56 | #endregion 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /XmlCodeGenerator/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /XmlCodeGenerator/overview.md: -------------------------------------------------------------------------------- 1 | # XmlCodeGeneartor 2 | 3 | ## Introduce 4 | 5 | C#/VB.NET code can be generated by XML + XSLT. 6 | 7 | ## What's New 8 | 9 | v1.0: Initial checked-in. 10 | 11 | v1.1: Add support for Visual Studio 2015 12 | 13 | v1.2: Add support for Visual Studio 2017 14 | 15 | v1.3: Add support for Visual Studio 2019 (Preview) 16 | 17 | ### How to use 18 | 19 | 1. Create your own XML file in your project. For example, 20 | 21 | ~~~~ 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | ~~~~ 30 | 31 | 2. Create your own XSLT file in the same directory of XML. You can write XSLT to produce source codes on XML. For example, 32 | 33 | ~~~~ 34 | 35 | 36 | 37 | 52 | 58 | 59 | ~~~~ 60 | 61 | 3. Finally, select Xml file and type 'XmlCodeGenerator' on 'Custom Tool' in properties. 62 | 63 | ![https://sysnetblobaccount.blob.core.windows.net/sysnetimages/xml_xslt.png](https://sysnetblobaccount.blob.core.windows.net/sysnetimages/xml_xslt.png) 64 | 65 | 4. Now, whenever you save xml file, [xml-filename].cs file will be generated by combining with XSLT. For example, 66 | 67 | ~~~~ 68 | using System; 69 | using System.Collections.Generic; 70 | using System.Text; 71 | namespace macroTest 72 | { 73 | public partial class Test 74 | { 75 | private void DoIt(int condition) 76 | { 77 | if (condition == 1) 78 | { 79 | funcName_1(); 80 | } 81 | // .........[repeat].......... 82 | } 83 | } 84 | } 85 | ~~~~ 86 | 87 | ### Source Code 88 | 89 | Project site: [https://github.com/stjeong/XmlCodeGenerator](https://github.com/stjeong/XmlCodeGenerator) -------------------------------------------------------------------------------- /XmlCodeGenerator/publishManifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/vsix-publish", 3 | "categories": [ 4 | "coding" 5 | ], 6 | "identity": { 7 | "internalName": "XmlCodeGenerator" 8 | }, 9 | "overview": "overview.md", 10 | "priceCategory": "free", 11 | "publisher": "SeongTaeJeong", 12 | "private": false, 13 | "qna": true, 14 | "repo": "https://github.com/stjeong/XmlCodeGenerator" 15 | } -------------------------------------------------------------------------------- /XmlCodeGenerator/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | XmlCodeGenerator 6 | Auto-generates source code with XML + XSLT 7 | https://github.com/stjeong/XmlCodeGenerator 8 | https://github.com/stjeong/XmlCodeGenerator 9 | xml_xslt.png 10 | Code Generator 11 | 12 | 13 | 14 | amd64 15 | 16 | 17 | amd64 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /XmlCodeGenerator/xml_xslt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stjeong/XmlCodeGenerator/7353271fdf315ef5b7d9c17bd96318ce8800c599/XmlCodeGenerator/xml_xslt.png -------------------------------------------------------------------------------- /XmlSrcGenerator/SourceGenerator.cs: -------------------------------------------------------------------------------- 1 | using BclExtension; 2 | using Microsoft.CodeAnalysis; 3 | using Microsoft.CodeAnalysis.Text; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using System.Globalization; 8 | using System.IO; 9 | using System.Text; 10 | using System.Xml; 11 | using System.Xml.Xsl; 12 | 13 | namespace XmlSrcGenerator 14 | { 15 | [Generator] 16 | public class SourceCodeGenerator : ISourceGenerator 17 | { 18 | static Dictionary xsltDict = new Dictionary(); 19 | internal const string DefaultXslFileName = "default.xslt"; 20 | 21 | public void Execute(SourceGeneratorContext context) 22 | { 23 | string fileNamespace = "ConsoleApp1"; // context.Compilation.GlobalNamespace.GetNamespaceMembers().First().ToDisplayString(); 24 | 25 | foreach (AdditionalText item in context.AdditionalFiles) 26 | { 27 | if (item.Path.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) == false) 28 | { 29 | continue; 30 | } 31 | 32 | string baseFolder = Path.GetDirectoryName(item.Path); 33 | 34 | string txt = GenerateCode(item.Path, fileNamespace, baseFolder); 35 | string fileName = Path.GetFileNameWithoutExtension(item.Path) + ".partial.xml"; 36 | 37 | context.AddSource(fileName, SourceText.From(txt, Encoding.UTF8)); 38 | } 39 | } 40 | 41 | public void Initialize(InitializationContext context) 42 | { 43 | } 44 | 45 | public string GenerateCode(string inputFileName, string fileNamespace, string baseFolder) 46 | { 47 | return Encoding.UTF8.GetString(GenerateCode(inputFileName, fileNamespace, baseFolder, string.Empty)); 48 | } 49 | 50 | protected byte[] GenerateCode(string inputFileName, string fileNamespace, string baseFolder, string inputFileContent) 51 | { 52 | string xmlFilePath = inputFileName; 53 | string xslFilePath = ResolveXSLPath(xmlFilePath, baseFolder); 54 | if (string.IsNullOrEmpty(xslFilePath) == true) 55 | { 56 | string msg = string.Format("// XSL File not found ({0})", xslFilePath); 57 | return System.Text.Encoding.UTF8.GetBytes(msg); 58 | } 59 | 60 | Debug.WriteLine("Original XmlFilePath: " + xmlFilePath); 61 | xmlFilePath = ResolveXmlPath(xmlFilePath); 62 | Debug.WriteLine("Resolved XmlFilePath: " + xmlFilePath); 63 | Debug.WriteLine("Resolved XslFilePath: " + xslFilePath); 64 | 65 | #if DEBUG 66 | string txt2 = File.ReadAllText(xslFilePath); 67 | #endif 68 | 69 | XslCompiledTransform xslt; 70 | XsltSettings xst = XsltSettings.Default; 71 | xst.EnableScript = true; 72 | 73 | try 74 | { 75 | string xsltText = File.ReadAllText(xslFilePath); 76 | 77 | // 재활용한다. 78 | if (xsltDict.TryGetValue(xsltText, out xslt) == false) 79 | { 80 | xslt = new XslCompiledTransform(); 81 | 82 | StringReader sr = new StringReader(xsltText); 83 | using (XmlReader xr = XmlReader.Create(sr)) 84 | { 85 | xslt.Load(xr, xst, null); 86 | } 87 | 88 | xsltDict.Add(xsltText, xslt); 89 | } 90 | } 91 | catch (Exception ex) 92 | { 93 | string output = string.Format("{0}{1}{2}", ex.Message, Environment.NewLine, ex.ToString()); 94 | return System.Text.Encoding.UTF8.GetBytes(output); 95 | } 96 | 97 | StringBuilder sb = new StringBuilder(); 98 | using (StringWriter sw = new StringWriter(sb, CultureInfo.CurrentCulture)) 99 | { 100 | XmlWriterSettings xws = new XmlWriterSettings(); 101 | xws.ConformanceLevel = ConformanceLevel.Auto; 102 | xws.Encoding = Encoding.UTF8; 103 | 104 | XmlReaderSettings xrs = new XmlReaderSettings(); 105 | 106 | XmlWriter writer = XmlTextWriter.Create(sw, xws); 107 | using (XmlReader reader = XmlReader.Create(xmlFilePath, xrs)) 108 | { 109 | XsltArgumentList xal = new XsltArgumentList(); 110 | // LoadXsltExtensionMethod(xal); 111 | xal.AddParam("XCG_CurrentTime", string.Empty, DateTime.Now.ToString(CultureInfo.InvariantCulture)); 112 | xal.AddParam("XCG_Namespace", string.Empty, fileNamespace); 113 | xal.AddParam("XCG_BaseFolder", string.Empty, baseFolder); 114 | xal.AddParam("XCG_Version", string.Empty, "1.0"); 115 | xslt.Transform(reader, xal, writer); 116 | } 117 | 118 | #if DEBUG 119 | string txt = sb.ToString(); 120 | #endif 121 | } 122 | 123 | return System.Text.Encoding.UTF8.GetBytes(sb.ToString()); 124 | } 125 | 126 | private static string ResolveXmlPath(string xmlFilePath) 127 | { 128 | XmlDocument xmlDoc = new XmlDocument(); 129 | xmlDoc.Load(xmlFilePath); 130 | 131 | string baseFolder = Path.GetDirectoryName(xmlFilePath); 132 | 133 | XmlNode sourceNode = xmlDoc.SelectSingleNode("//ExternalSource"); 134 | if (sourceNode == null) 135 | { 136 | return xmlFilePath; 137 | } 138 | 139 | return Path.Combine(baseFolder, sourceNode.InnerText); 140 | } 141 | 142 | private string ResolveXSLPath(string xmlFilePath, string baseFolder) 143 | { 144 | // 0: 만약 XML 파일안에 xcg-xsltKey Preprocessor 가 있다면 그를 따른다. 145 | XmlDocument document = new XmlDocument(); 146 | document.Load(xmlFilePath); 147 | XmlProcessingInstruction xcgPI = 148 | document.SelectSingleNode("/processing-instruction(\"xcg-xsltKey\")") 149 | as XmlProcessingInstruction; 150 | 151 | if (xcgPI != null) 152 | { 153 | return Path.Combine(baseFolder, xcgPI.Value) + ".xslt"; 154 | } 155 | 156 | // 0.1: 만약 XML 파일안에 xcg-xsltFileName Preprocessor 가 있다면 그를 따른다. 157 | xcgPI = document.SelectSingleNode("/processing-instruction(\"xcg-xsltFileName\")") as XmlProcessingInstruction; 158 | 159 | if (xcgPI != null) 160 | { 161 | string xmlFolder = Path.GetDirectoryName(xmlFilePath); 162 | return Path.Combine(xmlFolder, xcgPI.Value) + ".xslt"; 163 | } 164 | 165 | // 1: XML 파일에서 "xslt" 확장자만 교체해서 검색 166 | string xslFilePath = Path.ChangeExtension(xmlFilePath, "xslt"); 167 | if (File.Exists(xslFilePath) == true) 168 | { 169 | return xslFilePath; 170 | } 171 | 172 | // 2: 같은 폴더에서 파일명만 default.xslt 173 | string defaultXslFilePath = PathExtension.ChangeFileName(xslFilePath, DefaultXslFileName); 174 | if (File.Exists(defaultXslFilePath) == true) 175 | { 176 | return defaultXslFilePath; 177 | } 178 | 179 | // 3: 상위 폴더에서 루트 드라이브까지 파일명이 XML 파일에서 xslt 확장자만 교체한 것과 일치한 것을 검색 180 | string found = PathExtension.SearchInParents(xslFilePath); 181 | if (string.IsNullOrEmpty(found) == false) 182 | { 183 | return found; 184 | } 185 | 186 | // 4: 상위 폴더에서 루트 드라이브까지 파일명이 default.xslt 파일이 있는지 검사. 187 | return PathExtension.SearchInParents(defaultXslFilePath); 188 | } 189 | 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /XmlSrcGenerator/XmlSrcGenerator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 1.0.8 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | all 15 | runtime; build; native; contentfiles; analyzers; buildtransitive 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /XmlSrcGenerator/XmlSrcGenerator.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | XmlSrcGenerator 5 | C# Source Generator with XML + XSLT 6 | 1.0.8 7 | SeongTae Jeong 8 | false 9 | C# Source Generator with XML + XSLT (same as https://marketplace.visualstudio.com/items?itemName=SeongTaeJeong.XmlCodeGenerator) 10 | Analyzers CSharp xml xslt 11 | https://github.com/stjeong/XmlCodeGenerator 12 | MIT 13 | true 14 | 15 | -------------------------------------------------------------------------------- /XmlSrcGenerator/deploy_nuget.bat: -------------------------------------------------------------------------------- 1 | 2 | SET BUILDCONFIG=Release 3 | SET PRJNAME=XmlSrcGenerator 4 | 5 | if '%1' == 'local' SET BUILDCONFIG=Debug 6 | 7 | FOR /F %%I IN ("%0") DO SET CURRENTDIR=%%~dpI 8 | 9 | msbuild %CURRENTDIR%%PRJNAME%.csproj /p:Configuration=%BUILDCONFIG%;DefineConstants="TRACE" /t:Rebuild 10 | if ERRORLEVEL 1 goto BuildError 11 | 12 | robocopy %CURRENTDIR%bin\%BUILDCONFIG%\netstandard2.0 %CURRENTDIR%nuget\root\analyzers\dotnet\cs 13 | robocopy %CURRENTDIR% %CURRENTDIR%nuget\root %PRJNAME%.nuspec 14 | 15 | nuget pack %CURRENTDIR%\nuget\root\%PRJNAME%.nuspec -OutputDirectory %CURRENTDIR%nuget_output 16 | if %ERRORLEVEL% GTR 0 goto BuildError 17 | 18 | for /f %%i in ('powershell.exe -ExecutionPolicy RemoteSigned -file %CURRENTDIR%..\getNugetVersion.ps1 %CURRENTDIR%nuget\root\%PRJNAME%.nuspec') do set NUGETVERSION=%%i 19 | echo %NUGETVERSION% 20 | 21 | for /f %%i in ('powershell.exe -ExecutionPolicy RemoteSigned -file %CURRENTDIR%..\readFile.ps1 d:\settings\nuget_key.txt') do set NUGETKEY=%%i 22 | echo %NUGETKEY% 23 | 24 | if EXIST D:\myNuget\ ( 25 | robocopy %CURRENTDIR%nuget_output\ D:\myNuget %PRJNAME%.%NUGETVERSION%.nupkg 26 | if NOT '%NUGET_PACKAGES%' == '' ( 27 | if EXIST %NUGET_PACKAGES%\%PRJNAME%\%NUGETVERSION% ( 28 | rmdir %NUGET_PACKAGES%\%PRJNAME%\%NUGETVERSION% /S /Q 29 | ) 30 | ) 31 | ) ELSE ( 32 | echo No local nuget directory 33 | ) 34 | 35 | if '%1' == 'local' goto EndOfBuild 36 | 37 | nuget push %CURRENTDIR%nuget_output\%PRJNAME%.%NUGETVERSION%.nupkg %NUGETKEY% -src https://www.nuget.org/api/v2/package 38 | goto EndOfBuild 39 | 40 | :BuildError 41 | Echo Failed to build 42 | 43 | 44 | :EndOfBuild -------------------------------------------------------------------------------- /getNugetVersion.ps1: -------------------------------------------------------------------------------- 1 | param([String] $XMLFile) 2 | 3 | [XML]$nugetRoot = Get-Content $XMLfile 4 | 5 | Write-Host $nugetRoot.package.metadata.version -------------------------------------------------------------------------------- /introduce.txt: -------------------------------------------------------------------------------- 1 | 

XmlCodeGeneartor

2 |

3 |

Introduce
4 | 5 | C#/VB.NET code can be generated by XML + XSLT. 6 | 7 | 8 | 9 |
What's New
10 | 11 | V 1.0: Initial checked-in. 12 | 13 | 14 | 15 |
How to use
16 | 17 | 1. Create your own XML file in your project. For example, 18 | 19 |
20 | <IFs>
21 |     <DOIT condition="1" />
22 |     <DOIT condition="2" />
23 |     <DOIT condition="3" />
24 |     <DOIT condition="4" />
25 |     <DOIT condition="5" />
26 | </IFs>
27 | 
28 | 29 | 30 | 2. Create your own XSLT file in the same directory of XML. You can write XSLT to produce source codes on XML. For example, 31 | 32 |
33 | <?xml version="1.0" encoding="UTF-8" ?>
34 | <stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
35 | <output method="text"  encoding="utf-8" indent="yes"></output>
36 |     <template match="IFs">
37 |         using System;
38 |         using System.Collections.Generic;
39 |         using System.Text;
40 | 
41 |         namespace macroTest
42 |         {
43 |             public partial class Test
44 |             {
45 |                 private void DoIt(int condition)
46 |                 {
47 |                     <apply-templates select="//DOIT"></apply-templates>
48 |                 }
49 |             }
50 |         }
51 |     </template>
52 | 
53 |     <template match="//DOIT">
54 |         if (condition == <value-of select="@condition"/>)
55 |         {
56 |             funcName_<value-of select="@condition"/>();
57 |         }
58 |     </template>
59 | </stylesheet>
60 | 
61 | 62 | 63 | 3. Finally, select Xml file and type 'XmlCodeGenerator' on 'Custom Tool' in properties. 64 | 65 | http://res.sysnet.pe.kr/sysnetimages/xml_xslt.png 66 | 67 | 68 | 4. Now, whenever you save xml file, [xml-filename].cs file will be generated by combining with XSLT. For example, 69 | 70 |
71 |     using System;
72 |     using System.Collections.Generic;
73 |     using System.Text;dafdas
74 | 
75 |     namespace macroTest
76 |     {
77 |         public partial class Test
78 |         {
79 |         private void DoIt(int condition)
80 |         {
81 |     
82 |             if (condition == 1)
83 |             {
84 |             funcName_1();
85 |             }
86 |       
87 |             // .........[repeat]..........
88 |         }
89 |         }
90 |     }    
91 | 
92 | 93 |

94 | -------------------------------------------------------------------------------- /lib/Microsoft.VisualStudio.Interop.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stjeong/XmlCodeGenerator/7353271fdf315ef5b7d9c17bd96318ce8800c599/lib/Microsoft.VisualStudio.Interop.dll -------------------------------------------------------------------------------- /lib/Microsoft.VisualStudio.OLE.Interop.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stjeong/XmlCodeGenerator/7353271fdf315ef5b7d9c17bd96318ce8800c599/lib/Microsoft.VisualStudio.OLE.Interop.dll -------------------------------------------------------------------------------- /lib/Microsoft.VisualStudio.Shell.15.0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stjeong/XmlCodeGenerator/7353271fdf315ef5b7d9c17bd96318ce8800c599/lib/Microsoft.VisualStudio.Shell.15.0.dll -------------------------------------------------------------------------------- /lib/Microsoft.VisualStudio.Shell.Framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stjeong/XmlCodeGenerator/7353271fdf315ef5b7d9c17bd96318ce8800c599/lib/Microsoft.VisualStudio.Shell.Framework.dll -------------------------------------------------------------------------------- /lib/Microsoft.VisualStudio.TextTemplating.VSHost.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stjeong/XmlCodeGenerator/7353271fdf315ef5b7d9c17bd96318ce8800c599/lib/Microsoft.VisualStudio.TextTemplating.VSHost.dll -------------------------------------------------------------------------------- /lib/Microsoft.VisualStudio.Utilities.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stjeong/XmlCodeGenerator/7353271fdf315ef5b7d9c17bd96318ce8800c599/lib/Microsoft.VisualStudio.Utilities.dll -------------------------------------------------------------------------------- /readFile.ps1: -------------------------------------------------------------------------------- 1 | param([String] $filePath) 2 | 3 | 4 | $text = Get-Content $filePath 5 | 6 | Write-Host $text --------------------------------------------------------------------------------