DllExport.bat 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. @echo off
  2. :: Copyright (c) 2016-2018 Denis Kuzmin [ entry.reg@gmail.com ] :: github.com/3F
  3. :: https://github.com/3F/DllExport
  4. :: ---
  5. :: Based on hMSBuild logic and includes GetNuTool core.
  6. :: https://github.com/3F/hMSBuild
  7. :: https://github.com/3F/GetNuTool
  8. setlocal enableDelayedExpansion
  9. set "aa=1.6.1"
  10. set "wAction="
  11. set "ab=DllExport"
  12. set "ac=tools/net.r_eg.DllExport.Wizard.targets"
  13. set "ad=packages"
  14. set "ae=https://www.nuget.org/api/v2/package/"
  15. set "af=build_info.txt"
  16. set "wRootPath=%cd%"
  17. set wMgrArgs="%*"
  18. set /a ag=0
  19. set /a ah=0
  20. set "ai="
  21. set "aj="
  22. set "ak="
  23. set "al="
  24. set "am="
  25. set "an="
  26. set ao=0
  27. set ap=2
  28. set aq=3
  29. set "ar=%* "
  30. set "as=%~dpnx0"
  31. set at=%ar:"=%
  32. set au=%at%
  33. set au=%au:-help =%
  34. set au=%au:-h =%
  35. set au=%au:-? =%
  36. if not "%at%"=="%au%" goto bb
  37. goto bc
  38. :bb
  39. echo.
  40. @echo DllExport - v1.6.1.51910 [ e6c3d30 ]
  41. @echo Copyright (c) 2009-2015 Robert Giesecke
  42. @echo Copyright (c) 2016-2018 Denis Kuzmin [ entry.reg@gmail.com :: github.com/3F ]
  43. echo.
  44. echo Distributed under the MIT license
  45. @echo https://github.com/3F/DllExport
  46. echo Wizard - based on hMSBuild logic and includes GetNuTool core - https://github.com/3F
  47. echo.
  48. @echo.
  49. @echo Usage: DllExport [args to DllExport] [args to GetNuTool core]
  50. echo ------
  51. echo.
  52. echo Arguments:
  53. echo ----------
  54. echo -action {type} - Specified action for Wizard. Where {type}:
  55. echo * Configure - To configure DllExport for specific projects.
  56. echo * Update - To update pkg reference for already configured projects.
  57. echo * Restore - To restore configured DllExport.
  58. echo * Export - To export configured projects data.
  59. echo * Recover - To re-configure projects via predefined/exported data.
  60. echo * Unset - To unset all data from specified projects.
  61. echo * Upgrade - Aggregates an Update action with additions for upgrading.
  62. echo.
  63. echo -sln-dir {path} - Path to directory with .sln files to be processed.
  64. echo -sln-file {path} - Optional predefined .sln file to process via the restore operations etc.
  65. echo -metalib {path} - Relative path from PkgPath to DllExport meta library.
  66. echo -dxp-target {path} - Relative path to entrypoint wrapper of the main core.
  67. echo -dxp-version {num} - Specific version of DllExport. Where {num}:
  68. echo * Versions: 1.6.0 ...
  69. echo * Keywords:
  70. echo `actual` to use unspecified local version or to get latest available;
  71. echo.
  72. echo -msb {path} - Full path to specific msbuild.
  73. echo -packages {path} - A common directory for packages.
  74. echo -server {url} - Url for searching remote packages.
  75. echo -proxy {cfg} - To use proxy. The format: [usr[:pwd]@]host[:port]
  76. echo -pkg-link {uri} - Direct link to package from the source via specified URI.
  77. echo -force - Aggressive behavior, e.g. like removing pkg when updating.
  78. echo -mgr-up - Updates this manager to version from '-dxp-version'.
  79. echo -wz-target {path} - Relative path to entrypoint wrapper of the main wizard.
  80. echo -pe-exp-list {module} - To list all available exports from PE32/PE32+ module.
  81. echo -eng - Try to use english language for all build messages.
  82. echo -GetNuTool {args} - Access to GetNuTool core. https://github.com/3F/GetNuTool
  83. echo -debug - To show additional information.
  84. echo -version - Displays version for which (together with) it was compiled.
  85. echo -build-info - Displays actual build information from selected DllExport.
  86. echo -help - Displays this help. Aliases: -help -h -?
  87. echo.
  88. echo.
  89. echo --------
  90. echo Samples:
  91. echo --------
  92. echo DllExport -action Configure
  93. echo DllExport -action Restore -sln-file "Conari.sln"
  94. echo DllExport -proxy guest:1234@10.0.2.15:7428 -action Configure
  95. echo.
  96. echo DllExport -build-info
  97. echo DllExport -restore -sln-dir -sln-dir ..\ -debug
  98. echo.
  99. echo DllExport -GetNuTool -unpack
  100. echo DllExport -GetNuTool /p:ngpackages="Conari;regXwild"
  101. echo DllExport -pe-exp-list bin\Debug\regXwild.dll
  102. exit /B 0
  103. :bc
  104. call :bd ar _is
  105. if [!_is!]==[1] (
  106. if defined wAction goto be
  107. goto bb
  108. )
  109. set /a av=1 & set aw=20
  110. :bf
  111. if "!ar:~0,8!"=="-action " (
  112. call :bg %1 & shift
  113. set wAction=%2
  114. call :bg %2 & shift
  115. )
  116. if "!ar:~0,9!"=="-sln-dir " (
  117. call :bg %1 & shift
  118. set wSlnDir=%2
  119. call :bg %2 & shift
  120. )
  121. if "!ar:~0,10!"=="-sln-file " (
  122. call :bg %1 & shift
  123. set wSlnFile=%2
  124. call :bg %2 & shift
  125. )
  126. if "!ar:~0,9!"=="-metalib " (
  127. call :bg %1 & shift
  128. set wMetaLib=%2
  129. call :bg %2 & shift
  130. )
  131. if "!ar:~0,12!"=="-dxp-target " (
  132. call :bg %1 & shift
  133. set wDxpTarget=%2
  134. call :bg %2 & shift
  135. )
  136. if "!ar:~0,13!"=="-dxp-version " (
  137. call :bg %1 & shift
  138. set aa=%2
  139. call :bg %2 & shift
  140. )
  141. if "!ar:~0,5!"=="-msb " (
  142. call :bg %1 & shift
  143. set ai=%2
  144. call :bg %2 & shift
  145. )
  146. if "!ar:~0,10!"=="-packages " (
  147. call :bg %1 & shift
  148. set ad=%2
  149. set "ad=!ad:"=!"
  150. call :bg %2 & shift
  151. )
  152. if "!ar:~0,8!"=="-server " (
  153. call :bg %1 & shift
  154. set ae=%2
  155. call :bg %2 & shift
  156. )
  157. if "!ar:~0,7!"=="-proxy " (
  158. call :bg %1 & shift
  159. set an=%2
  160. call :bg %2 & shift
  161. )
  162. if "!ar:~0,10!"=="-pkg-link " (
  163. call :bg %1 & shift
  164. set aj=%2
  165. call :bg %2 & shift
  166. )
  167. if "!ar:~0,7!"=="-force " (
  168. call :bg %1 & shift
  169. set /a al=1
  170. )
  171. if "!ar:~0,8!"=="-mgr-up " (
  172. call :bg %1 & shift
  173. set /a am=1
  174. )
  175. if "!ar:~0,11!"=="-wz-target " (
  176. call :bg %1 & shift
  177. set ac=%2
  178. call :bg %2 & shift
  179. )
  180. if "!ar:~0,13!"=="-pe-exp-list " (
  181. call :bg %1 & shift
  182. set ak=%2
  183. call :bg %2 & shift
  184. )
  185. if "!ar:~0,5!"=="-eng " (
  186. call :bg %1 & shift
  187. chcp 437 >nul
  188. )
  189. if "!ar:~0,11!"=="-GetNuTool " (
  190. call :bg %1 & shift
  191. goto bh
  192. )
  193. if "!ar:~0,7!"=="-debug " (
  194. call :bg %1 & shift
  195. set /a ag=1
  196. )
  197. if "!ar:~0,9!"=="-version " (
  198. @echo v1.6.1.51910 [ e6c3d30 ]
  199. exit /B 0
  200. )
  201. if "!ar:~0,12!"=="-build-info " (
  202. call :bg %1 & shift
  203. set /a ah=1
  204. )
  205. set /a "av+=1"
  206. if !av! LSS %aw% goto bf
  207. goto be
  208. :bg
  209. set ar=!!ar:%1 ^=!!
  210. call :bi ar
  211. set "ar=!ar! "
  212. exit /B 0
  213. :be
  214. call :bj "dxpName = '%ab%'"
  215. call :bj "dxpVersion = '!aa!'"
  216. if defined aa (
  217. if "!aa!"=="actual" (
  218. set "aa="
  219. )
  220. )
  221. if z%wAction%==zUpgrade (
  222. call :bj "Upgrade is on"
  223. set /a am=1
  224. set /a al=1
  225. )
  226. call :bi ad
  227. set "ad=!ad!\\"
  228. set "ax=!ab!"
  229. set "wPkgPath=!ad!!ab!"
  230. if defined aa (
  231. set "ax=!ax!/!aa!"
  232. set "wPkgPath=!wPkgPath!.!aa!"
  233. )
  234. if defined al (
  235. if exist "!wPkgPath!" (
  236. call :bj "Removing old version '!wPkgPath!' before continue. '-force' key rule."
  237. rmdir /S/Q "!wPkgPath!"
  238. )
  239. )
  240. set ay="!wPkgPath!\\!ac!"
  241. call :bj "dxpTarget = '!ay!'"
  242. if not exist !ay! (
  243. if exist "!wPkgPath!" (
  244. call :bj "Wizard was not found. Trying to replace obsolete version '!wPkgPath!' ..."
  245. rmdir /S/Q "!wPkgPath!"
  246. )
  247. call :bj "-pkg-link = '!aj!'"
  248. call :bj "-server = '!ae!'"
  249. if defined aj (
  250. set ae=!aj!
  251. if "!wPkgPath::=!"=="!wPkgPath!" (
  252. set "az=../"
  253. )
  254. set "ax=:!az!!wPkgPath!"
  255. )
  256. call :bj "_remoteUrl = '!ax!'"
  257. call :bj "ngpath = '!ad!'"
  258. if defined ai (
  259. set a0=-msbuild !ai!
  260. )
  261. set a1=!a0! /p:ngserver="!ae!" /p:ngpackages="!ax!" /p:proxycfg="!an!"
  262. if "!ag!"=="1" (
  263. call :bk !a1!
  264. ) else (
  265. call :bk !a1! >nul
  266. )
  267. )
  268. if defined ak (
  269. !wPkgPath!\\tools\\PeViewer.exe -list -pemodule "!ak!"
  270. exit /B %ERRORLEVEL%
  271. )
  272. if "!ah!"=="1" (
  273. call :bj "buildInfo = '!wPkgPath!\\!af!'"
  274. if not exist "!wPkgPath!\\!af!" (
  275. echo information about build is not available.
  276. exit /B %ap%
  277. )
  278. type "!wPkgPath!\\!af!"
  279. exit /B 0
  280. )
  281. if not exist !ay! (
  282. echo Something went wrong. Try to use another keys.
  283. exit /B %ap%
  284. )
  285. call :bj "-sln-dir = '!wSlnDir!'"
  286. call :bj "-sln-file = '!wSlnFile!'"
  287. call :bj "-metalib = '!wMetaLib!'"
  288. call :bj "-dxp-target = '!wDxpTarget!'"
  289. call :bj "wRootPath = !wRootPath!"
  290. call :bj "wAction = !wAction!"
  291. if defined ai (
  292. set "ai=%ai:"=%"
  293. call :bj "Use specific MSBuild tools '!ai!'"
  294. set a2=!ai!
  295. goto bl
  296. )
  297. call :bm
  298. if "!ERRORLEVEL!"=="0" goto bl
  299. echo MSBuild tools was not found. Try with `-msb` key. `-help` for details.
  300. exit /B %ap%
  301. :bl
  302. call :bd a2 _is
  303. if [!_is!]==[1] (
  304. echo Something went wrong. Use `-debug` key for details.
  305. exit /B %ap%
  306. )
  307. set a3="!a2!"
  308. call :bj "Target: '!a2!' !ay!"
  309. !a3! /nologo /v:m /m:4 !ay!
  310. if defined am (
  311. (copy /B/Y "!wPkgPath!\\DllExport.bat" "%as%" > nul) & echo Manager has been updated. & exit /B 0
  312. )
  313. exit /B 0
  314. :bm
  315. call :bj "trying via MSBuild tools from .NET Framework - .net 4.0, ..."
  316. for %%v in (4.0, 3.5, 2.0) do (
  317. call :bn %%v Y & if [!Y!]==[1] exit /B 0
  318. )
  319. call :bj "msbnetf: unfortunately we didn't find anything."
  320. exit /B %ap%
  321. :bn
  322. call :bj "checking of version: %1"
  323. for /F "usebackq tokens=2* skip=2" %%a in (
  324. `reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%1" /v MSBuildToolsPath 2^> nul`
  325. ) do if exist %%b (
  326. call :bj "found: %%b"
  327. set a2=%%b
  328. call :bo
  329. set /a %2=1
  330. exit /B 0
  331. )
  332. set /a %2=0
  333. exit /B 0
  334. :bh
  335. call :bj "direct access to GetNuTool..."
  336. call :bk !ar!
  337. exit /B 0
  338. :bo
  339. set a2=!a2!\MSBuild.exe
  340. exit /B 0
  341. :bj
  342. if "!ag!"=="1" (
  343. set a4=%1
  344. set a4=!a4:~0,-1!
  345. set a4=!a4:~1!
  346. echo.[%TIME% ] !a4!
  347. )
  348. exit /B 0
  349. :bi
  350. call :a6 %%%1%%
  351. set %1=%a5%
  352. exit /B 0
  353. :a6
  354. set "a5=%*"
  355. exit /B 0
  356. :bd
  357. setlocal enableDelayedExpansion
  358. set "a6=!%1!"
  359. if not defined a6 endlocal & set /a %2=1 & exit /B 0
  360. set a6=%a6: =%
  361. set "a6= %a6%"
  362. if [^%a6:~1,1%]==[] endlocal & set /a %2=1 & exit /B 0
  363. endlocal & set /a %2=0
  364. exit /B 0
  365. :bk
  366. setlocal disableDelayedExpansion
  367. @echo off
  368. :: GetNuTool - Executable version
  369. :: Copyright (c) 2015-2018 Denis Kuzmin [ entry.reg@gmail.com ]
  370. :: https://github.com/3F/GetNuTool
  371. set a7=gnt.core
  372. set a8="%temp%\%random%%random%%a7%"
  373. set "ar=%* "
  374. set a=%ar:~0,30%
  375. set a=%a:"=%
  376. if "%a:~0,8%"=="-unpack " goto bp
  377. if "%a:~0,9%"=="-msbuild " goto bq
  378. for %%v in (4.0, 14.0, 12.0, 3.5, 2.0) do (
  379. for /F "usebackq tokens=2* skip=2" %%a in (
  380. `reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%%v" /v MSBuildToolsPath 2^> nul`
  381. ) do if exist %%b (
  382. set a9="%%b\MSBuild.exe"
  383. goto br
  384. )
  385. )
  386. echo MSBuild was not found, try: gnt -msbuild "fullpath" args 1>&2
  387. exit /B 2
  388. :bq
  389. call :bs %1
  390. shift
  391. set a9=%1
  392. call :bs %1
  393. :br
  394. call :bt
  395. %a9% %a8% /nologo /p:wpath="%~dp0/" /v:m %ar%
  396. del /Q/F %a8%
  397. exit /B 0
  398. :bs
  399. call set ar=%%ar:%1 ^=%%
  400. exit /B 0
  401. :bp
  402. set a8="%~dp0\%a7%"
  403. echo Generate minified version in %a8% ...
  404. :bt
  405. <nul set /P ="">%a8%
  406. <nul set /P =^<!-- GetNuTool - github.com/3F/GetNuTool --^>^<!-- Copyright (c) 2015-2018 Denis Kuzmin [ entry.reg@gmail.com ] --^>^<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"^>^<PropertyGroup^>^<ngconfig Condition="'$(ngconfig)' == ''"^>packages.config^</ngconfig^>^<ngserver Condition="'$(ngserver)' == ''"^>https://www.nuget.org/api/v2/package/^</ngserver^>^<ngpackages Condition="'$(ngpackages)' == ''"^>^</ngpackages^>^<ngpath Condition="'$(ngpath)' == ''"^>packages^</ngpath^>^</PropertyGroup^>^<Target Name="get" BeforeTargets="Build" DependsOnTargets="header"^>^<PrepareList config="$(ngconfig)" plist="$(ngpackages)" wpath="$(wpath)"^>^<Output PropertyName="plist" TaskParameter="Result"/^>^</PrepareList^>^<NGDownload plist="$(plist)" url="$(ngserver)" wpath="$(wpath)" defpath="$(ngpath)" proxy="$(proxycfg)" debug="$(debug)"/^>^</Target^>^<Target Name="pack" DependsOnTargets="header"^>^<NGPack dir="$(ngin)" dout="$(ngout)" wpath="$(wpath)" vtool="$(GetNuTool)" debug="$(debug)"/^>^</Target^>^<PropertyGroup^>^<TaskCoreDllPath Condition="Exists('$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll')"^>$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll^</TaskCoreDllPath^>^<TaskCoreDllPath Condition="'$(TaskCoreDllPath)' == '' and Exists('$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll')"^>$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll^</TaskCoreDllPath^>^</PropertyGroup^>^<UsingTask TaskName="PrepareList" TaskFactory="CodeTaskFactory" AssemblyFile="$(TaskCoreDllPath)"^>^<ParameterGr>> %a8%
  407. <nul set /P =oup^>^<config ParameterType="System.String" Required="true"/^>^<plist ParameterType="System.String"/^>^<wpath ParameterType="System.String"/^>^<Result ParameterType="System.String" Output="true"/^>^</ParameterGroup^>^<Task^>^<Reference Include="System.Xml"/^>^<Reference Include="System.Xml.Linq"/^>^<Using Namespace="System"/^>^<Using Namespace="System.Collections.Generic"/^>^<Using Namespace="System.IO"/^>^<Using Namespace="System.Xml.Linq"/^>^<Code Type="Fragment" Language="cs"^>^<![CDATA[if(!String.IsNullOrEmpty(plist)){Result=plist;return true;}var _err=Console.Error;Action^<string,Queue^<string^>^> h=delegate(string cfg,Queue^<string^> list){foreach(var pkg in XDocument.Load(cfg).Descendants("package")){var id=pkg.Attribute("id");var version=pkg.Attribute("version");var output=pkg.Attribute("output");if(id==null){_err.WriteLine("Some 'id' does not exist in '{0}'",cfg);return;}var link=id.Value;if(version!=null){link+="/"+version.Value;}if(output!=null){list.Enqueue(link+":"+output.Value);continue;}list.Enqueue(link);}};var ret=new Queue^<string^>();foreach(var cfg in config.Split('^|',';')){var lcfg=Path.Combine(wpath,cfg??"");if(File.Exists(lcfg)){h(lcfg,ret);}else{_err.WriteLine(".config '{0}' was not found.",lcfg);}}if(ret.Count ^< 1){_err.WriteLine("List of packages is empty. Use .config or /p:ngpackages=\"...\"\n");}else{Result=String.Join(";",ret.ToArray());}]]^>^</Code^>^</Task^>^</UsingTask^>^<UsingTask TaskName="NGDownload" TaskFactory="CodeTaskFactory" AssemblyFile="$(TaskCoreDllPath)"^>^<ParameterGroup^>^<plist ParameterType="System.String">> %a8%
  408. <nul set /P =/^>^<url ParameterType="System.String" Required="true"/^>^<wpath ParameterType="System.String"/^>^<defpath ParameterType="System.String"/^>^<proxy ParameterType="System.String"/^>^<debug ParameterType="System.Boolean"/^>^</ParameterGroup^>^<Task^>^<Reference Include="WindowsBase"/^>^<Using Namespace="System"/^>^<Using Namespace="System.IO"/^>^<Using Namespace="System.IO.Packaging"/^>^<Using Namespace="System.Net"/^>^<Code Type="Fragment" Language="cs"^>^<![CDATA[if(plist==null){return false;}ServicePointManager.SecurityProtocol ^|=SecurityProtocolType.Tls11 ^| SecurityProtocolType.Tls12;var ignore=new string[]{"/_rels/","/package/","/[Content_Types].xml"};Action^<string,object^> dbg=delegate(string s,object p){if(debug){Console.WriteLine(s,p);}};Func^<string,WebProxy^> getProxy=delegate(string cfg){var auth=cfg.Split('@');if(auth.Length ^<=1){return new WebProxy(auth[0],false);}var login=auth[0].Split(':');return new WebProxy(auth[1],false){Credentials=new NetworkCredential(login[0],(login.Length ^> 1)?login[1]: null)};};Func^<string,string^> loc=delegate(string p){return Path.Combine(wpath,p??"");};Action^<string,string,string^> get=delegate(string link,string name,string path){var to=Path.GetFullPath(loc(path??name));if(Directory.Exists(to)){Console.WriteLine("`{0}` is already exists: \"{1}\"",name,to);return;}Console.Write("Getting `{0}` ... ",link);var tmp=Path.Combine(Path.GetTempPath(),Guid.NewGuid().ToString());using(var l=new WebClient()){try{if(proxy!=null){l.Proxy=getProxy(proxy);}l.Headers.Add("User-Agent","GetNuTool");l.UseDefaultCredentia>> %a8%
  409. <nul set /P =ls=true;l.DownloadFile(url+link,tmp);}catch(Exception ex){Console.Error.WriteLine(ex.Message);return;}}Console.WriteLine("Extracting into \"{0}\"",to);using(var pkg=ZipPackage.Open(tmp,FileMode.Open,FileAccess.Read)){foreach(var part in pkg.GetParts()){var uri=Uri.UnescapeDataString(part.Uri.OriginalString);if(ignore.Any(x=^> uri.StartsWith(x,StringComparison.Ordinal))){continue;}var dest=Path.Combine(to,uri.TrimStart('/'));dbg("- `{0}`",uri);var dir=Path.GetDirectoryName(dest);if(!Directory.Exists(dir)){Directory.CreateDirectory(dir);}using(var src=part.GetStream(FileMode.Open,FileAccess.Read))using(var target=File.OpenWrite(dest)){try{src.CopyTo(target);}catch(FileFormatException ex){dbg("[x]?crc: {0}",dest);}}}}File.Delete(tmp);};foreach(var pkg in plist.Split(';')){var ident=pkg.Split(new char[]{':'},2);var link=ident[0];var path=(ident.Length ^> 1)?ident[1]: null;var name=link.Replace('/','.');if(!String.IsNullOrEmpty(defpath)){path=Path.Combine(defpath,path??name);}get(link,name,path);}]]^>^</Code^>^</Task^>^</UsingTask^>^<UsingTask TaskName="NGPack" TaskFactory="CodeTaskFactory" AssemblyFile="$(TaskCoreDllPath)"^>^<ParameterGroup^>^<dir ParameterType="System.String" Required="true"/^>^<dout ParameterType="System.String"/^>^<wpath ParameterType="System.String"/^>^<vtool ParameterType="System.String" Required="true"/^>^<debug ParameterType="System.Boolean"/^>^</ParameterGroup^>^<Task^>^<Reference Include="System.Xml"/^>^<Reference Include="System.Xml.Linq"/^>^<Reference Include="WindowsBase"/^>^<Using Namespace="System"/^>^<Using Namespace="System.Collections.Generic">> %a8%
  410. <nul set /P =/^>^<Using Namespace="System.IO"/^>^<Using Namespace="System.Linq"/^>^<Using Namespace="System.IO.Packaging"/^>^<Using Namespace="System.Xml.Linq"/^>^<Using Namespace="System.Text.RegularExpressions"/^>^<Code Type="Fragment" Language="cs"^>^<![CDATA[var EXT_NUSPEC=".nuspec";var EXT_NUPKG=".nupkg";var TAG_META="metadata";var DEF_CONTENT_TYPE="application/octet";var MANIFEST_URL="http://schemas.microsoft.com/packaging/2010/07/manifest";var ID="id";var VER="version";Action^<string,object^> dbg=delegate(string s,object p){if(debug){Console.WriteLine(s,p);}};var _err=Console.Error;dir=Path.Combine(wpath,dir);if(!Directory.Exists(dir)){_err.WriteLine("`{0}` was not found.",dir);return false;}dout=Path.Combine(wpath,dout??"");var nuspec=Directory.GetFiles(dir,"*"+EXT_NUSPEC,SearchOption.TopDirectoryOnly).FirstOrDefault();if(nuspec==null){_err.WriteLine("{0} was not found in `{1}`",EXT_NUSPEC,dir);return false;}Console.WriteLine("Found {0}: `{1}`",EXT_NUSPEC,nuspec);var root=XDocument.Load(nuspec).Root.Elements().FirstOrDefault(x=^> x.Name.LocalName==TAG_META);if(root==null){_err.WriteLine("{0} does not contain {1}.",nuspec,TAG_META);return false;}var metadata=new Dictionary^<string,string^>();foreach(var tag in root.Elements()){metadata[tag.Name.LocalName.ToLower()]=tag.Value;}if(metadata[ID].Length ^> 100 ^|^|!Regex.IsMatch(metadata[ID],@"^\w+([_.-]\w+)*$",RegexOptions.IgnoreCase ^| RegexOptions.ExplicitCapture)){_err.WriteLine("The format of `{0}` is not correct.",ID);return false;}var ignore=new string[]{Path.Combine(dir,"_rels"),Path.Combine(dir,"package">> %a8%
  411. <nul set /P =),Path.Combine(dir,"[Content_Types].xml")};var pout=String.Format("{0}.{1}{2}",metadata[ID],metadata[VER],EXT_NUPKG);if(!String.IsNullOrWhiteSpace(dout)){if(!Directory.Exists(dout)){Directory.CreateDirectory(dout);}pout=Path.Combine(dout,pout);}Console.WriteLine("Started packing `{0}` ...",pout);using(var pkg=Package.Open(pout,FileMode.Create)){var manifestUri=new Uri(String.Format("/{0}{1}",metadata[ID],EXT_NUSPEC),UriKind.Relative);pkg.CreateRelationship(manifestUri,TargetMode.Internal,MANIFEST_URL);foreach(var file in Directory.GetFiles(dir,"*.*",SearchOption.AllDirectories)){if(ignore.Any(x=^> file.StartsWith(x,StringComparison.Ordinal))){continue;}string pUri;if(file.StartsWith(dir,StringComparison.OrdinalIgnoreCase)){pUri=file.Substring(dir.Length).TrimStart(Path.DirectorySeparatorChar);}else{pUri=file;}dbg("- `{0}`",pUri);var escaped=String.Join("/",pUri.Split('\\','/').Select(p=^> Uri.EscapeDataString(p)));var uri=PackUriHelper.CreatePartUri(new Uri(escaped,UriKind.Relative));var part=pkg.CreatePart(uri,DEF_CONTENT_TYPE,CompressionOption.Maximum);using(var tstream=part.GetStream())using(var fs=new FileStream(file,FileMode.Open,FileAccess.Read)){fs.CopyTo(tstream);}}Func^<string,string^> getmeta=delegate(string key){return(metadata.ContainsKey(key))?metadata[key]:"";};var _p=pkg.PackageProperties;_p.Creator=getmeta("authors");_p.Description=getmeta("description");_p.Identifier=metadata[ID];_p.Version=metadata[VER];_p.Keywords=getmeta("tags");_p.Title=getmeta("title");_p.LastModifiedBy="GetNuTool v"+vtool;}]]^>^</Code^>^</Task^>^</UsingTask^>^<T>> %a8%
  412. <nul set /P =arget Name="Build" DependsOnTargets="get"/^>^<PropertyGroup^>^<GetNuTool^>1.6.2.1354_e910e5c^</GetNuTool^>^<wpath Condition="'$(wpath)' == ''"^>$(MSBuildProjectDirectory)^</wpath^>^</PropertyGroup^>^<Target Name="header"^>^<Message Text="%%0D%%0AGetNuTool v$(GetNuTool) - github.com/3F%%0D%%0A=========%%0D%%0A" Importance="high"/^>^</Target^>^</Project^>>> %a8%
  413. exit /B 0