├── .gitignore ├── LICENSE ├── Native.NETHostFxr ├── ManagedLibrary │ ├── ManagedLibrary.csproj │ └── ManagedWorker.cs ├── Native.NETHostFxr.sln ├── Native.NETHostFxr │ ├── Native.NETHostFxr.vcxproj │ ├── Native.NETHostFxr.vcxproj.filters │ └── main.cpp └── lib │ └── netcore │ ├── Native.NETHostFxr.runtimeconfig.json │ ├── bin │ ├── comhost.dll │ ├── ijwhost.dll │ └── nethost.dll │ ├── includes │ ├── coreclr_delegates.h │ ├── hostfxr.h │ └── nethost.h │ └── lib │ ├── ijwhost.lib │ ├── libnethost.lib │ └── nethost.lib └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | docs 352 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More_considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution 4.0 International Public License 58 | 59 | By exercising the Licensed Rights (defined below), You accept and agree 60 | to be bound by the terms and conditions of this Creative Commons 61 | Attribution 4.0 International Public License ("Public License"). To the 62 | extent this Public License may be interpreted as a contract, You are 63 | granted the Licensed Rights in consideration of Your acceptance of 64 | these terms and conditions, and the Licensor grants You such rights in 65 | consideration of benefits the Licensor receives from making the 66 | Licensed Material available under these terms and conditions. 67 | 68 | 69 | Section 1 -- Definitions. 70 | 71 | a. Adapted Material means material subject to Copyright and Similar 72 | Rights that is derived from or based upon the Licensed Material 73 | and in which the Licensed Material is translated, altered, 74 | arranged, transformed, or otherwise modified in a manner requiring 75 | permission under the Copyright and Similar Rights held by the 76 | Licensor. For purposes of this Public License, where the Licensed 77 | Material is a musical work, performance, or sound recording, 78 | Adapted Material is always produced where the Licensed Material is 79 | synched in timed relation with a moving image. 80 | 81 | b. Adapter's License means the license You apply to Your Copyright 82 | and Similar Rights in Your contributions to Adapted Material in 83 | accordance with the terms and conditions of this Public License. 84 | 85 | c. Copyright and Similar Rights means copyright and/or similar rights 86 | closely related to copyright including, without limitation, 87 | performance, broadcast, sound recording, and Sui Generis Database 88 | Rights, without regard to how the rights are labeled or 89 | categorized. For purposes of this Public License, the rights 90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 91 | Rights. 92 | 93 | d. Effective Technological Measures means those measures that, in the 94 | absence of proper authority, may not be circumvented under laws 95 | fulfilling obligations under Article 11 of the WIPO Copyright 96 | Treaty adopted on December 20, 1996, and/or similar international 97 | agreements. 98 | 99 | e. Exceptions and Limitations means fair use, fair dealing, and/or 100 | any other exception or limitation to Copyright and Similar Rights 101 | that applies to Your use of the Licensed Material. 102 | 103 | f. Licensed Material means the artistic or literary work, database, 104 | or other material to which the Licensor applied this Public 105 | License. 106 | 107 | g. Licensed Rights means the rights granted to You subject to the 108 | terms and conditions of this Public License, which are limited to 109 | all Copyright and Similar Rights that apply to Your use of the 110 | Licensed Material and that the Licensor has authority to license. 111 | 112 | h. Licensor means the individual(s) or entity(ies) granting rights 113 | under this Public License. 114 | 115 | i. Share means to provide material to the public by any means or 116 | process that requires permission under the Licensed Rights, such 117 | as reproduction, public display, public performance, distribution, 118 | dissemination, communication, or importation, and to make material 119 | available to the public including in ways that members of the 120 | public may access the material from a place and at a time 121 | individually chosen by them. 122 | 123 | j. Sui Generis Database Rights means rights other than copyright 124 | resulting from Directive 96/9/EC of the European Parliament and of 125 | the Council of 11 March 1996 on the legal protection of databases, 126 | as amended and/or succeeded, as well as other essentially 127 | equivalent rights anywhere in the world. 128 | 129 | k. You means the individual or entity exercising the Licensed Rights 130 | under this Public License. Your has a corresponding meaning. 131 | 132 | 133 | Section 2 -- Scope. 134 | 135 | a. License grant. 136 | 137 | 1. Subject to the terms and conditions of this Public License, 138 | the Licensor hereby grants You a worldwide, royalty-free, 139 | non-sublicensable, non-exclusive, irrevocable license to 140 | exercise the Licensed Rights in the Licensed Material to: 141 | 142 | a. reproduce and Share the Licensed Material, in whole or 143 | in part; and 144 | 145 | b. produce, reproduce, and Share Adapted Material. 146 | 147 | 2. Exceptions and Limitations. For the avoidance of doubt, where 148 | Exceptions and Limitations apply to Your use, this Public 149 | License does not apply, and You do not need to comply with 150 | its terms and conditions. 151 | 152 | 3. Term. The term of this Public License is specified in Section 153 | 6(a). 154 | 155 | 4. Media and formats; technical modifications allowed. The 156 | Licensor authorizes You to exercise the Licensed Rights in 157 | all media and formats whether now known or hereafter created, 158 | and to make technical modifications necessary to do so. The 159 | Licensor waives and/or agrees not to assert any right or 160 | authority to forbid You from making technical modifications 161 | necessary to exercise the Licensed Rights, including 162 | technical modifications necessary to circumvent Effective 163 | Technological Measures. For purposes of this Public License, 164 | simply making modifications authorized by this Section 2(a) 165 | (4) never produces Adapted Material. 166 | 167 | 5. Downstream recipients. 168 | 169 | a. Offer from the Licensor -- Licensed Material. Every 170 | recipient of the Licensed Material automatically 171 | receives an offer from the Licensor to exercise the 172 | Licensed Rights under the terms and conditions of this 173 | Public License. 174 | 175 | b. No downstream restrictions. You may not offer or impose 176 | any additional or different terms or conditions on, or 177 | apply any Effective Technological Measures to, the 178 | Licensed Material if doing so restricts exercise of the 179 | Licensed Rights by any recipient of the Licensed 180 | Material. 181 | 182 | 6. No endorsement. Nothing in this Public License constitutes or 183 | may be construed as permission to assert or imply that You 184 | are, or that Your use of the Licensed Material is, connected 185 | with, or sponsored, endorsed, or granted official status by, 186 | the Licensor or others designated to receive attribution as 187 | provided in Section 3(a)(1)(A)(i). 188 | 189 | b. Other rights. 190 | 191 | 1. Moral rights, such as the right of integrity, are not 192 | licensed under this Public License, nor are publicity, 193 | privacy, and/or other similar personality rights; however, to 194 | the extent possible, the Licensor waives and/or agrees not to 195 | assert any such rights held by the Licensor to the limited 196 | extent necessary to allow You to exercise the Licensed 197 | Rights, but not otherwise. 198 | 199 | 2. Patent and trademark rights are not licensed under this 200 | Public License. 201 | 202 | 3. To the extent possible, the Licensor waives any right to 203 | collect royalties from You for the exercise of the Licensed 204 | Rights, whether directly or through a collecting society 205 | under any voluntary or waivable statutory or compulsory 206 | licensing scheme. In all other cases the Licensor expressly 207 | reserves any right to collect such royalties. 208 | 209 | 210 | Section 3 -- License Conditions. 211 | 212 | Your exercise of the Licensed Rights is expressly made subject to the 213 | following conditions. 214 | 215 | a. Attribution. 216 | 217 | 1. If You Share the Licensed Material (including in modified 218 | form), You must: 219 | 220 | a. retain the following if it is supplied by the Licensor 221 | with the Licensed Material: 222 | 223 | i. identification of the creator(s) of the Licensed 224 | Material and any others designated to receive 225 | attribution, in any reasonable manner requested by 226 | the Licensor (including by pseudonym if 227 | designated); 228 | 229 | ii. a copyright notice; 230 | 231 | iii. a notice that refers to this Public License; 232 | 233 | iv. a notice that refers to the disclaimer of 234 | warranties; 235 | 236 | v. a URI or hyperlink to the Licensed Material to the 237 | extent reasonably practicable; 238 | 239 | b. indicate if You modified the Licensed Material and 240 | retain an indication of any previous modifications; and 241 | 242 | c. indicate the Licensed Material is licensed under this 243 | Public License, and include the text of, or the URI or 244 | hyperlink to, this Public License. 245 | 246 | 2. You may satisfy the conditions in Section 3(a)(1) in any 247 | reasonable manner based on the medium, means, and context in 248 | which You Share the Licensed Material. For example, it may be 249 | reasonable to satisfy the conditions by providing a URI or 250 | hyperlink to a resource that includes the required 251 | information. 252 | 253 | 3. If requested by the Licensor, You must remove any of the 254 | information required by Section 3(a)(1)(A) to the extent 255 | reasonably practicable. 256 | 257 | 4. If You Share Adapted Material You produce, the Adapter's 258 | License You apply must not prevent recipients of the Adapted 259 | Material from complying with this Public License. 260 | 261 | 262 | Section 4 -- Sui Generis Database Rights. 263 | 264 | Where the Licensed Rights include Sui Generis Database Rights that 265 | apply to Your use of the Licensed Material: 266 | 267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 268 | to extract, reuse, reproduce, and Share all or a substantial 269 | portion of the contents of the database; 270 | 271 | b. if You include all or a substantial portion of the database 272 | contents in a database in which You have Sui Generis Database 273 | Rights, then the database in which You have Sui Generis Database 274 | Rights (but not its individual contents) is Adapted Material; and 275 | 276 | c. You must comply with the conditions in Section 3(a) if You Share 277 | all or a substantial portion of the contents of the database. 278 | 279 | For the avoidance of doubt, this Section 4 supplements and does not 280 | replace Your obligations under this Public License where the Licensed 281 | Rights include other Copyright and Similar Rights. 282 | 283 | 284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 285 | 286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 296 | 297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 306 | 307 | c. The disclaimer of warranties and limitation of liability provided 308 | above shall be interpreted in a manner that, to the extent 309 | possible, most closely approximates an absolute disclaimer and 310 | waiver of all liability. 311 | 312 | 313 | Section 6 -- Term and Termination. 314 | 315 | a. This Public License applies for the term of the Copyright and 316 | Similar Rights licensed here. However, if You fail to comply with 317 | this Public License, then Your rights under this Public License 318 | terminate automatically. 319 | 320 | b. Where Your right to use the Licensed Material has terminated under 321 | Section 6(a), it reinstates: 322 | 323 | 1. automatically as of the date the violation is cured, provided 324 | it is cured within 30 days of Your discovery of the 325 | violation; or 326 | 327 | 2. upon express reinstatement by the Licensor. 328 | 329 | For the avoidance of doubt, this Section 6(b) does not affect any 330 | right the Licensor may have to seek remedies for Your violations 331 | of this Public License. 332 | 333 | c. For the avoidance of doubt, the Licensor may also offer the 334 | Licensed Material under separate terms or conditions or stop 335 | distributing the Licensed Material at any time; however, doing so 336 | will not terminate this Public License. 337 | 338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 339 | License. 340 | 341 | 342 | Section 7 -- Other Terms and Conditions. 343 | 344 | a. The Licensor shall not be bound by any additional or different 345 | terms or conditions communicated by You unless expressly agreed. 346 | 347 | b. Any arrangements, understandings, or agreements regarding the 348 | Licensed Material not stated herein are separate from and 349 | independent of the terms and conditions of this Public License. 350 | 351 | 352 | Section 8 -- Interpretation. 353 | 354 | a. For the avoidance of doubt, this Public License does not, and 355 | shall not be interpreted to, reduce, limit, restrict, or impose 356 | conditions on any use of the Licensed Material that could lawfully 357 | be made without permission under this Public License. 358 | 359 | b. To the extent possible, if any provision of this Public License is 360 | deemed unenforceable, it shall be automatically reformed to the 361 | minimum extent necessary to make it enforceable. If the provision 362 | cannot be reformed, it shall be severed from this Public License 363 | without affecting the enforceability of the remaining terms and 364 | conditions. 365 | 366 | c. No term or condition of this Public License will be waived and no 367 | failure to comply consented to unless expressly agreed to by the 368 | Licensor. 369 | 370 | d. Nothing in this Public License constitutes or may be interpreted 371 | as a limitation upon, or waiver of, any privileges and immunities 372 | that apply to the Licensor or You, including from the legal 373 | processes of any jurisdiction or authority. 374 | 375 | 376 | ======================================================================= 377 | 378 | Creative Commons is not a party to its public 379 | licenses. Notwithstanding, Creative Commons may elect to apply one of 380 | its public licenses to material it publishes and in those instances 381 | will be considered the "Licensor." The text of the Creative Commons 382 | public licenses is dedicated to the public domain under the CC0 Public 383 | Domain Dedication. Except for the limited purpose of indicating that 384 | material is shared under a Creative Commons public license or as 385 | otherwise permitted by the Creative Commons policies published at 386 | creativecommons.org/policies, Creative Commons does not authorize the 387 | use of the trademark "Creative Commons" or any other trademark or logo 388 | of Creative Commons without its prior written consent including, 389 | without limitation, in connection with any unauthorized modifications 390 | to any of its public licenses or any other arrangements, 391 | understandings, or agreements concerning use of licensed material. For 392 | the avoidance of doubt, this paragraph does not form part of the 393 | public licenses. 394 | 395 | Creative Commons may be contacted at creativecommons.org. -------------------------------------------------------------------------------- /Native.NETHostFxr/ManagedLibrary/ManagedLibrary.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | x64 6 | 7 | 8 | 9 | $(SolutionDir)bin\$(Configuration)-$(Platform)\ 10 | x64 11 | 12 | 13 | false 14 | false 15 | 16 | 17 | $(SolutionDir)bin\$(Configuration)-$(Platform)\ 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Native.NETHostFxr/ManagedLibrary/ManagedWorker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace ManagedLibrary 5 | { 6 | public class ManagedWorker 7 | { 8 | // Marked as "UnmanagedCallersOnly" so that we don't have to specify a delegate 9 | // when getting a function pointer to it on the CPP side 10 | [UnmanagedCallersOnly] 11 | public static void Print() 12 | { 13 | Console.WriteLine("ManagedWorker.Print()"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Native.NETHostFxr/Native.NETHostFxr.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31321.278 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Native.NETHostFxr", "Native.NETHostFxr\Native.NETHostFxr.vcxproj", "{DDFA0071-E414-494B-908C-983851355399}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {EBAFBC79-A833-4CC4-9F5B-47C3CE14C464} = {EBAFBC79-A833-4CC4-9F5B-47C3CE14C464} 9 | EndProjectSection 10 | EndProject 11 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagedLibrary", "ManagedLibrary\ManagedLibrary.csproj", "{EBAFBC79-A833-4CC4-9F5B-47C3CE14C464}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|x64 = Debug|x64 16 | Release|x64 = Release|x64 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {DDFA0071-E414-494B-908C-983851355399}.Debug|x64.ActiveCfg = Debug|x64 20 | {DDFA0071-E414-494B-908C-983851355399}.Debug|x64.Build.0 = Debug|x64 21 | {DDFA0071-E414-494B-908C-983851355399}.Release|x64.ActiveCfg = Release|x64 22 | {DDFA0071-E414-494B-908C-983851355399}.Release|x64.Build.0 = Release|x64 23 | {EBAFBC79-A833-4CC4-9F5B-47C3CE14C464}.Debug|x64.ActiveCfg = Debug|x64 24 | {EBAFBC79-A833-4CC4-9F5B-47C3CE14C464}.Debug|x64.Build.0 = Debug|x64 25 | {EBAFBC79-A833-4CC4-9F5B-47C3CE14C464}.Release|x64.ActiveCfg = Release|x64 26 | {EBAFBC79-A833-4CC4-9F5B-47C3CE14C464}.Release|x64.Build.0 = Release|x64 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | GlobalSection(ExtensibilityGlobals) = postSolution 32 | SolutionGuid = {1286DA8D-CE02-43E1-8883-FF7202BA0AAF} 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /Native.NETHostFxr/Native.NETHostFxr/Native.NETHostFxr.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | 16.0 15 | Win32Proj 16 | {ddfa0071-e414-494b-908c-983851355399} 17 | NativeNETHostFxr 18 | 10.0 19 | 20 | 21 | 22 | Application 23 | true 24 | v142 25 | Unicode 26 | 27 | 28 | Application 29 | false 30 | v142 31 | true 32 | Unicode 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | true 48 | $(SolutionDir)bin\$(Configuration)-$(Platform)\ 49 | $(SolutionDir).tmp\$(Configuration)-$(Platform)\ 50 | $(SolutionDir)lib\netcore\includes;$(IncludePath) 51 | $(SolutionDir)lib\netcore\lib;$(LibraryPath) 52 | 53 | 54 | false 55 | $(SolutionDir)bin\$(Configuration)-$(Platform)\ 56 | $(SolutionDir).tmp\$(Configuration)-$(Platform)\ 57 | $(SolutionDir)lib\netcore\includes;$(IncludePath) 58 | $(SolutionDir)lib\netcore\lib;$(LibraryPath) 59 | 60 | 61 | 62 | Level3 63 | true 64 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 65 | true 66 | stdcpp17 67 | MultiThreadedDebug 68 | 69 | 70 | Console 71 | true 72 | nethost.lib;ijwhost.lib;libnethost.lib;shlwapi.lib;%(AdditionalDependencies) 73 | 74 | 75 | xcopy /s /r /y /q "$(SolutionDir)lib\netcore\bin" "$(OutDir)" 76 | xcopy /s /r /y /q "$(SolutionDir)lib\netcore\Native.NETHostFxr.runtimeconfig.json" "$(OutDir)" 77 | 78 | 79 | 80 | 81 | Level3 82 | true 83 | true 84 | true 85 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 86 | true 87 | stdcpp17 88 | 89 | 90 | Console 91 | true 92 | true 93 | true 94 | nethost.lib;ijwhost.lib;libnethost.lib;shlwapi.lib;%(AdditionalDependencies) 95 | 96 | 97 | xcopy /s /r /y /q "$(SolutionDir)lib\netcore\bin" "$(OutDir)" 98 | xcopy /s /r /y /q "$(SolutionDir)lib\netcore\Native.NETHostFxr.runtimeconfig.json" "$(OutDir)" 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /Native.NETHostFxr/Native.NETHostFxr/Native.NETHostFxr.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /Native.NETHostFxr/Native.NETHostFxr/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using string_t = std::basic_string; 11 | 12 | namespace 13 | { 14 | // Globals to hold hostfxr exports 15 | hostfxr_initialize_for_runtime_config_fn init_runtimeCfg_fptr; 16 | hostfxr_get_runtime_delegate_fn get_delegate_fptr; 17 | hostfxr_close_fn close_fptr; 18 | 19 | // Handles 20 | hostfxr_handle cxt = nullptr; 21 | 22 | // Forward declarations 23 | load_assembly_and_get_function_pointer_fn get_dotnet_load_assembly(const char_t *assembly); 24 | bool load_hostfxr(); 25 | void* load_library(const char_t* path); 26 | void* get_export(void* h, const char* name); 27 | } 28 | 29 | 30 | int main() 31 | { 32 | // STEP 0: Get the current executable directory 33 | string_t runtimePath(MAX_PATH, '\0'); 34 | GetModuleFileNameW(nullptr, runtimePath.data(), MAX_PATH); 35 | PathRemoveFileSpecW(runtimePath.data()); 36 | // Since PathRemoveFileSpecA() removes from data(), the size is not updated, so we must manually update it 37 | runtimePath.resize(std::wcslen(runtimePath.data())); 38 | 39 | // STEP 1: Load HostFxr and get exported hosting functions 40 | if (!load_hostfxr()) 41 | { 42 | assert(false && "Failure: load_hostfxr()"); 43 | return EXIT_FAILURE; 44 | } 45 | 46 | // STEP 2: Initialize and start the .NET Core runtime 47 | const string_t config_path = runtimePath + L"\\Native.NETHostFxr.runtimeconfig.json"; 48 | int rc = init_runtimeCfg_fptr(config_path.c_str(), nullptr, &cxt); 49 | if (rc != 0 || cxt == nullptr) 50 | { 51 | std::cerr << "Init failed: " << std::hex << std::showbase << rc << std::endl; 52 | close_fptr(cxt); 53 | return EXIT_FAILURE; 54 | } 55 | load_assembly_and_get_function_pointer_fn load_assembly_and_get_function_pointer = get_dotnet_load_assembly(config_path.c_str()); 56 | assert(load_assembly_and_get_function_pointer != nullptr && "Failure: get_dotnet_load_assembly()"); 57 | 58 | // STEP 3: Load managed assembly and get function pointer to a managed method 59 | const string_t dotnetlib_path = runtimePath + L"\\ManagedLibrary.dll"; 60 | const char_t *dotnet_type = L"ManagedLibrary.ManagedWorker, ManagedLibrary"; 61 | 62 | typedef void (CORECLR_DELEGATE_CALLTYPE *custom_entry_point_fn)(void); 63 | custom_entry_point_fn custom = nullptr; 64 | rc = load_assembly_and_get_function_pointer 65 | ( 66 | dotnetlib_path.c_str(), 67 | dotnet_type, 68 | L"Print", /* Function Name */ 69 | UNMANAGEDCALLERSONLY_METHOD, 70 | nullptr, 71 | (void**)&custom 72 | ); 73 | assert(rc == 0 && custom != nullptr && "Failure: load_assembly_and_get_function_pointer()"); 74 | 75 | // STEP 4: Run managed code 76 | custom(); 77 | 78 | // STEP 5: Shut Down NET Core runtime 79 | close_fptr(cxt); 80 | } 81 | namespace 82 | { 83 | bool load_hostfxr() 84 | { 85 | // Pre-allocate a large buffer for the path to hostfxr 86 | char_t buffer[MAX_PATH]; 87 | size_t buffer_size = sizeof(buffer) / sizeof(char_t); 88 | int rc = get_hostfxr_path(buffer, &buffer_size, nullptr); 89 | if (rc != 0) 90 | return false; 91 | 92 | // Load hostfxr and get desired exports 93 | void* lib = load_library(buffer); 94 | init_runtimeCfg_fptr = (hostfxr_initialize_for_runtime_config_fn)get_export(lib, "hostfxr_initialize_for_runtime_config"); 95 | get_delegate_fptr = (hostfxr_get_runtime_delegate_fn)get_export(lib, "hostfxr_get_runtime_delegate"); 96 | close_fptr = (hostfxr_close_fn)get_export(lib, "hostfxr_close"); 97 | 98 | return (init_runtimeCfg_fptr && get_delegate_fptr && close_fptr); 99 | } 100 | 101 | void *load_library(const char_t *path) 102 | { 103 | HMODULE h = ::LoadLibraryW(path); 104 | assert(h != nullptr); 105 | return (void*)h; 106 | } 107 | 108 | void *get_export(void *h, const char *name) 109 | { 110 | void *f = ::GetProcAddress((HMODULE)h, name); 111 | assert(f != nullptr); 112 | return f; 113 | } 114 | 115 | // Load and initialize .NET Core and get desired function pointer for scenario 116 | load_assembly_and_get_function_pointer_fn get_dotnet_load_assembly(const char_t *config_path) 117 | { 118 | void *load_assembly_and_get_function_pointer = nullptr; 119 | 120 | 121 | // Get the load assembly function pointer 122 | int rc = get_delegate_fptr( 123 | cxt, 124 | hdt_load_assembly_and_get_function_pointer, 125 | &load_assembly_and_get_function_pointer); 126 | if (rc != 0 || load_assembly_and_get_function_pointer == nullptr) 127 | std::cerr << "Get delegate failed: " << std::hex << std::showbase << rc << std::endl; 128 | 129 | return (load_assembly_and_get_function_pointer_fn)load_assembly_and_get_function_pointer; 130 | } 131 | } -------------------------------------------------------------------------------- /Native.NETHostFxr/lib/netcore/Native.NETHostFxr.runtimeconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeOptions": { 3 | "tfm": "net5.0", 4 | "framework": { 5 | "name": "Microsoft.NETCore.App", 6 | "version": "5.0.6" 7 | }, 8 | "configProperties": { 9 | "System.GC.Concurrent": false, 10 | "System.Threading.ThreadPool.MinThreads": 4, 11 | "System.Threading.ThreadPool.MaxThreads": 25 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Native.NETHostFxr/lib/netcore/bin/comhost.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycorax/.NET-Core-HostWithHostFxr-Sample/d891346d92661076c05ccb23d2facc5bf11b836f/Native.NETHostFxr/lib/netcore/bin/comhost.dll -------------------------------------------------------------------------------- /Native.NETHostFxr/lib/netcore/bin/ijwhost.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycorax/.NET-Core-HostWithHostFxr-Sample/d891346d92661076c05ccb23d2facc5bf11b836f/Native.NETHostFxr/lib/netcore/bin/ijwhost.dll -------------------------------------------------------------------------------- /Native.NETHostFxr/lib/netcore/bin/nethost.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycorax/.NET-Core-HostWithHostFxr-Sample/d891346d92661076c05ccb23d2facc5bf11b836f/Native.NETHostFxr/lib/netcore/bin/nethost.dll -------------------------------------------------------------------------------- /Native.NETHostFxr/lib/netcore/includes/coreclr_delegates.h: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | #ifndef __CORECLR_DELEGATES_H__ 5 | #define __CORECLR_DELEGATES_H__ 6 | 7 | #include 8 | 9 | #if defined(_WIN32) 10 | #define CORECLR_DELEGATE_CALLTYPE __stdcall 11 | #ifdef _WCHAR_T_DEFINED 12 | typedef wchar_t char_t; 13 | #else 14 | typedef unsigned short char_t; 15 | #endif 16 | #else 17 | #define CORECLR_DELEGATE_CALLTYPE 18 | typedef char char_t; 19 | #endif 20 | 21 | #define UNMANAGEDCALLERSONLY_METHOD ((const char_t*)-1) 22 | 23 | // Signature of delegate returned by coreclr_delegate_type::load_assembly_and_get_function_pointer 24 | typedef int (CORECLR_DELEGATE_CALLTYPE *load_assembly_and_get_function_pointer_fn)( 25 | const char_t *assembly_path /* Fully qualified path to assembly */, 26 | const char_t *type_name /* Assembly qualified type name */, 27 | const char_t *method_name /* Public static method name compatible with delegateType */, 28 | const char_t *delegate_type_name /* Assembly qualified delegate type name or null 29 | or UNMANAGEDCALLERSONLY_METHOD if the method is marked with 30 | the UnmanagedCallersOnlyAttribute. */, 31 | void *reserved /* Extensibility parameter (currently unused and must be 0) */, 32 | /*out*/ void **delegate /* Pointer where to store the function pointer result */); 33 | 34 | // Signature of delegate returned by load_assembly_and_get_function_pointer_fn when delegate_type_name == null (default) 35 | typedef int (CORECLR_DELEGATE_CALLTYPE *component_entry_point_fn)(void *arg, int32_t arg_size_in_bytes); 36 | 37 | typedef int (CORECLR_DELEGATE_CALLTYPE *get_function_pointer_fn)( 38 | const char_t *type_name /* Assembly qualified type name */, 39 | const char_t *method_name /* Public static method name compatible with delegateType */, 40 | const char_t *delegate_type_name /* Assembly qualified delegate type name or null, 41 | or UNMANAGEDCALLERSONLY_METHOD if the method is marked with 42 | the UnmanagedCallersOnlyAttribute. */, 43 | void *load_context /* Extensibility parameter (currently unused and must be 0) */, 44 | void *reserved /* Extensibility parameter (currently unused and must be 0) */, 45 | /*out*/ void **delegate /* Pointer where to store the function pointer result */); 46 | 47 | #endif // __CORECLR_DELEGATES_H__ 48 | -------------------------------------------------------------------------------- /Native.NETHostFxr/lib/netcore/includes/hostfxr.h: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | #ifndef __HOSTFXR_H__ 5 | #define __HOSTFXR_H__ 6 | 7 | #include 8 | #include 9 | 10 | #if defined(_WIN32) 11 | #define HOSTFXR_CALLTYPE __cdecl 12 | #ifdef _WCHAR_T_DEFINED 13 | typedef wchar_t char_t; 14 | #else 15 | typedef unsigned short char_t; 16 | #endif 17 | #else 18 | #define HOSTFXR_CALLTYPE 19 | typedef char char_t; 20 | #endif 21 | 22 | enum hostfxr_delegate_type 23 | { 24 | hdt_com_activation, 25 | hdt_load_in_memory_assembly, 26 | hdt_winrt_activation, 27 | hdt_com_register, 28 | hdt_com_unregister, 29 | hdt_load_assembly_and_get_function_pointer, 30 | hdt_get_function_pointer, 31 | }; 32 | 33 | typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_main_fn)(const int argc, const char_t **argv); 34 | typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_main_startupinfo_fn)( 35 | const int argc, 36 | const char_t **argv, 37 | const char_t *host_path, 38 | const char_t *dotnet_root, 39 | const char_t *app_path); 40 | typedef int32_t(HOSTFXR_CALLTYPE* hostfxr_main_bundle_startupinfo_fn)( 41 | const int argc, 42 | const char_t** argv, 43 | const char_t* host_path, 44 | const char_t* dotnet_root, 45 | const char_t* app_path, 46 | int64_t bundle_header_offset); 47 | 48 | typedef void(HOSTFXR_CALLTYPE *hostfxr_error_writer_fn)(const char_t *message); 49 | 50 | // 51 | // Sets a callback which is to be used to write errors to. 52 | // 53 | // Parameters: 54 | // error_writer 55 | // A callback function which will be invoked every time an error is to be reported. 56 | // Or nullptr to unregister previously registered callback and return to the default behavior. 57 | // Return value: 58 | // The previously registered callback (which is now unregistered), or nullptr if no previous callback 59 | // was registered 60 | // 61 | // The error writer is registered per-thread, so the registration is thread-local. On each thread 62 | // only one callback can be registered. Subsequent registrations overwrite the previous ones. 63 | // 64 | // By default no callback is registered in which case the errors are written to stderr. 65 | // 66 | // Each call to the error writer is sort of like writing a single line (the EOL character is omitted). 67 | // Multiple calls to the error writer may occure for one failure. 68 | // 69 | // If the hostfxr invokes functions in hostpolicy as part of its operation, the error writer 70 | // will be propagated to hostpolicy for the duration of the call. This means that errors from 71 | // both hostfxr and hostpolicy will be reporter through the same error writer. 72 | // 73 | typedef hostfxr_error_writer_fn(HOSTFXR_CALLTYPE *hostfxr_set_error_writer_fn)(hostfxr_error_writer_fn error_writer); 74 | 75 | typedef void* hostfxr_handle; 76 | struct hostfxr_initialize_parameters 77 | { 78 | size_t size; 79 | const char_t *host_path; 80 | const char_t *dotnet_root; 81 | }; 82 | 83 | // 84 | // Initializes the hosting components for a dotnet command line running an application 85 | // 86 | // Parameters: 87 | // argc 88 | // Number of argv arguments 89 | // argv 90 | // Command-line arguments for running an application (as if through the dotnet executable). 91 | // parameters 92 | // Optional. Additional parameters for initialization 93 | // host_context_handle 94 | // On success, this will be populated with an opaque value representing the initialized host context 95 | // 96 | // Return value: 97 | // Success - Hosting components were successfully initialized 98 | // HostInvalidState - Hosting components are already initialized 99 | // 100 | // This function parses the specified command-line arguments to determine the application to run. It will 101 | // then find the corresponding .runtimeconfig.json and .deps.json with which to resolve frameworks and 102 | // dependencies and prepare everything needed to load the runtime. 103 | // 104 | // This function only supports arguments for running an application. It does not support SDK commands. 105 | // 106 | // This function does not load the runtime. 107 | // 108 | typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_initialize_for_dotnet_command_line_fn)( 109 | int argc, 110 | const char_t **argv, 111 | const struct hostfxr_initialize_parameters *parameters, 112 | /*out*/ hostfxr_handle *host_context_handle); 113 | 114 | // 115 | // Initializes the hosting components using a .runtimeconfig.json file 116 | // 117 | // Parameters: 118 | // runtime_config_path 119 | // Path to the .runtimeconfig.json file 120 | // parameters 121 | // Optional. Additional parameters for initialization 122 | // host_context_handle 123 | // On success, this will be populated with an opaque value representing the initialized host context 124 | // 125 | // Return value: 126 | // Success - Hosting components were successfully initialized 127 | // Success_HostAlreadyInitialized - Config is compatible with already initialized hosting components 128 | // Success_DifferentRuntimeProperties - Config has runtime properties that differ from already initialized hosting components 129 | // CoreHostIncompatibleConfig - Config is incompatible with already initialized hosting components 130 | // 131 | // This function will process the .runtimeconfig.json to resolve frameworks and prepare everything needed 132 | // to load the runtime. It will only process the .deps.json from frameworks (not any app/component that 133 | // may be next to the .runtimeconfig.json). 134 | // 135 | // This function does not load the runtime. 136 | // 137 | // If called when the runtime has already been loaded, this function will check if the specified runtime 138 | // config is compatible with the existing runtime. 139 | // 140 | // Both Success_HostAlreadyInitialized and Success_DifferentRuntimeProperties codes are considered successful 141 | // initializations. In the case of Success_DifferentRuntimeProperties, it is left to the consumer to verify that 142 | // the difference in properties is acceptable. 143 | // 144 | typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_initialize_for_runtime_config_fn)( 145 | const char_t *runtime_config_path, 146 | const struct hostfxr_initialize_parameters *parameters, 147 | /*out*/ hostfxr_handle *host_context_handle); 148 | 149 | // 150 | // Gets the runtime property value for an initialized host context 151 | // 152 | // Parameters: 153 | // host_context_handle 154 | // Handle to the initialized host context 155 | // name 156 | // Runtime property name 157 | // value 158 | // Out parameter. Pointer to a buffer with the property value. 159 | // 160 | // Return value: 161 | // The error code result. 162 | // 163 | // The buffer pointed to by value is owned by the host context. The lifetime of the buffer is only 164 | // guaranteed until any of the below occur: 165 | // - a 'run' method is called for the host context 166 | // - properties are changed via hostfxr_set_runtime_property_value 167 | // - the host context is closed via 'hostfxr_close' 168 | // 169 | // If host_context_handle is nullptr and an active host context exists, this function will get the 170 | // property value for the active host context. 171 | // 172 | typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_get_runtime_property_value_fn)( 173 | const hostfxr_handle host_context_handle, 174 | const char_t *name, 175 | /*out*/ const char_t **value); 176 | 177 | // 178 | // Sets the value of a runtime property for an initialized host context 179 | // 180 | // Parameters: 181 | // host_context_handle 182 | // Handle to the initialized host context 183 | // name 184 | // Runtime property name 185 | // value 186 | // Value to set 187 | // 188 | // Return value: 189 | // The error code result. 190 | // 191 | // Setting properties is only supported for the first host context, before the runtime has been loaded. 192 | // 193 | // If the property already exists in the host context, it will be overwritten. If value is nullptr, the 194 | // property will be removed. 195 | // 196 | typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_set_runtime_property_value_fn)( 197 | const hostfxr_handle host_context_handle, 198 | const char_t *name, 199 | const char_t *value); 200 | 201 | // 202 | // Gets all the runtime properties for an initialized host context 203 | // 204 | // Parameters: 205 | // host_context_handle 206 | // Handle to the initialized host context 207 | // count 208 | // [in] Size of the keys and values buffers 209 | // [out] Number of properties returned (size of keys/values buffers used). If the input value is too 210 | // small or keys/values is nullptr, this is populated with the number of available properties 211 | // keys 212 | // Array of pointers to buffers with runtime property keys 213 | // values 214 | // Array of pointers to buffers with runtime property values 215 | // 216 | // Return value: 217 | // The error code result. 218 | // 219 | // The buffers pointed to by keys and values are owned by the host context. The lifetime of the buffers is only 220 | // guaranteed until any of the below occur: 221 | // - a 'run' method is called for the host context 222 | // - properties are changed via hostfxr_set_runtime_property_value 223 | // - the host context is closed via 'hostfxr_close' 224 | // 225 | // If host_context_handle is nullptr and an active host context exists, this function will get the 226 | // properties for the active host context. 227 | // 228 | typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_get_runtime_properties_fn)( 229 | const hostfxr_handle host_context_handle, 230 | /*inout*/ size_t * count, 231 | /*out*/ const char_t **keys, 232 | /*out*/ const char_t **values); 233 | 234 | // 235 | // Load CoreCLR and run the application for an initialized host context 236 | // 237 | // Parameters: 238 | // host_context_handle 239 | // Handle to the initialized host context 240 | // 241 | // Return value: 242 | // If the app was successfully run, the exit code of the application. Otherwise, the error code result. 243 | // 244 | // The host_context_handle must have been initialized using hostfxr_initialize_for_dotnet_command_line. 245 | // 246 | // This function will not return until the managed application exits. 247 | // 248 | typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_run_app_fn)(const hostfxr_handle host_context_handle); 249 | 250 | // 251 | // Gets a typed delegate from the currently loaded CoreCLR or from a newly created one. 252 | // 253 | // Parameters: 254 | // host_context_handle 255 | // Handle to the initialized host context 256 | // type 257 | // Type of runtime delegate requested 258 | // delegate 259 | // An out parameter that will be assigned the delegate. 260 | // 261 | // Return value: 262 | // The error code result. 263 | // 264 | // If the host_context_handle was initialized using hostfxr_initialize_for_runtime_config, 265 | // then all delegate types are supported. 266 | // If the host_context_handle was initialized using hostfxr_initialize_for_dotnet_command_line, 267 | // then only the following delegate types are currently supported: 268 | // hdt_load_assembly_and_get_function_pointer 269 | // hdt_get_function_pointer 270 | // 271 | typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_get_runtime_delegate_fn)( 272 | const hostfxr_handle host_context_handle, 273 | enum hostfxr_delegate_type type, 274 | /*out*/ void **delegate); 275 | 276 | // 277 | // Closes an initialized host context 278 | // 279 | // Parameters: 280 | // host_context_handle 281 | // Handle to the initialized host context 282 | // 283 | // Return value: 284 | // The error code result. 285 | // 286 | typedef int32_t(HOSTFXR_CALLTYPE *hostfxr_close_fn)(const hostfxr_handle host_context_handle); 287 | 288 | #endif //__HOSTFXR_H__ 289 | -------------------------------------------------------------------------------- /Native.NETHostFxr/lib/netcore/includes/nethost.h: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | #ifndef __NETHOST_H__ 5 | #define __NETHOST_H__ 6 | 7 | #include 8 | 9 | #ifdef _WIN32 10 | #ifdef NETHOST_EXPORT 11 | #define NETHOST_API __declspec(dllexport) 12 | #else 13 | // Consuming the nethost as a static library 14 | // Shouldn't export attempt to dllimport. 15 | #ifdef NETHOST_USE_AS_STATIC 16 | #define NETHOST_API 17 | #else 18 | #define NETHOST_API __declspec(dllimport) 19 | #endif 20 | #endif 21 | 22 | #define NETHOST_CALLTYPE __stdcall 23 | #ifdef _WCHAR_T_DEFINED 24 | typedef wchar_t char_t; 25 | #else 26 | typedef unsigned short char_t; 27 | #endif 28 | #else 29 | #ifdef NETHOST_EXPORT 30 | #define NETHOST_API __attribute__((__visibility__("default"))) 31 | #else 32 | #define NETHOST_API 33 | #endif 34 | 35 | #define NETHOST_CALLTYPE 36 | typedef char char_t; 37 | #endif 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | // Parameters for get_hostfxr_path 44 | // 45 | // Fields: 46 | // size 47 | // Size of the struct. This is used for versioning. 48 | // 49 | // assembly_path 50 | // Path to the compenent's assembly. 51 | // If specified, hostfxr is located as if the assembly_path is the apphost 52 | // 53 | // dotnet_root 54 | // Path to directory containing the dotnet executable. 55 | // If specified, hostfxr is located as if an application is started using 56 | // 'dotnet app.dll', which means it will be searched for under the dotnet_root 57 | // path and the assembly_path is ignored. 58 | // 59 | struct get_hostfxr_parameters { 60 | size_t size; 61 | const char_t *assembly_path; 62 | const char_t *dotnet_root; 63 | }; 64 | 65 | // 66 | // Get the path to the hostfxr library 67 | // 68 | // Parameters: 69 | // buffer 70 | // Buffer that will be populated with the hostfxr path, including a null terminator. 71 | // 72 | // buffer_size 73 | // [in] Size of buffer in char_t units. 74 | // [out] Size of buffer used in char_t units. If the input value is too small 75 | // or buffer is nullptr, this is populated with the minimum required size 76 | // in char_t units for a buffer to hold the hostfxr path 77 | // 78 | // get_hostfxr_parameters 79 | // Optional. Parameters that modify the behaviour for locating the hostfxr library. 80 | // If nullptr, hostfxr is located using the enviroment variable or global registration 81 | // 82 | // Return value: 83 | // 0 on success, otherwise failure 84 | // 0x80008098 - buffer is too small (HostApiBufferTooSmall) 85 | // 86 | // Remarks: 87 | // The full search for the hostfxr library is done on every call. To minimize the need 88 | // to call this function multiple times, pass a large buffer (e.g. PATH_MAX). 89 | // 90 | NETHOST_API int NETHOST_CALLTYPE get_hostfxr_path( 91 | char_t * buffer, 92 | size_t * buffer_size, 93 | const struct get_hostfxr_parameters *parameters); 94 | 95 | #ifdef __cplusplus 96 | } // extern "C" 97 | #endif 98 | 99 | #endif // __NETHOST_H__ 100 | -------------------------------------------------------------------------------- /Native.NETHostFxr/lib/netcore/lib/ijwhost.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycorax/.NET-Core-HostWithHostFxr-Sample/d891346d92661076c05ccb23d2facc5bf11b836f/Native.NETHostFxr/lib/netcore/lib/ijwhost.lib -------------------------------------------------------------------------------- /Native.NETHostFxr/lib/netcore/lib/libnethost.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycorax/.NET-Core-HostWithHostFxr-Sample/d891346d92661076c05ccb23d2facc5bf11b836f/Native.NETHostFxr/lib/netcore/lib/libnethost.lib -------------------------------------------------------------------------------- /Native.NETHostFxr/lib/netcore/lib/nethost.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pycorax/.NET-Core-HostWithHostFxr-Sample/d891346d92661076c05ccb23d2facc5bf11b836f/Native.NETHostFxr/lib/netcore/lib/nethost.lib -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # .NET Core Host with HostFxr Sample 2 | 3 | This is a sample Visual Studio project for a x86-64 Windows native C++ application that is able to call functions in a .NET 5.0 library written in C#. The code here is based off Microsoft's sample here: https://github.com/dotnet/samples/tree/main/core/hosting/HostWithHostFxr 4 | 5 | This was built in order to attempt to integrate the .NET Core runtime into a Windows-only game engine written in C++ that I am working on, hence, the Windows-only support and absence of Linux-relevant code when compared to Microsoft's sample. 6 | 7 | This sample was built and tested on Visual Studio 2019 with the following workloads: 8 | - Desktop development with C++ 9 | - .NET cross-platform development 10 | 11 | I was unable to install the `Microsoft.NETCore.DotNetAppHost` package from nuget so instead, I had manually downloaded the corresponding runtime (`runtime.win-x64.Microsoft.NETCore.DotNetAppHost`) for it and extracted it out into the `Native.NETHostFxr/lib/netcore` folder. The version used is [5.0.6](https://www.nuget.org/packages/runtime.win-x64.Microsoft.NETCore.DotNetAppHost/5.0.6). --------------------------------------------------------------------------------