diff --git a/.gitignore b/.gitignore index 5f23ab8..050e6d3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ obj *.nupkg /tests/packages /tests/T00LS -/demo/wrappers/packages \ No newline at end of file +/demo/wrappers/packages +/demo/packages +/demo/*.sln diff --git a/.vssbe b/.vssbe index c963c25..c210320 100644 --- a/.vssbe +++ b/.vssbe @@ -1548,6 +1548,19 @@ " true", ")]", "", + "", + "#[$(demoPath = \"$(odir)\\demo\\batch\\\\\")]", + "#[$(tpackages = '.tools\\packages.config')]", + "", + "#[$(vssbePkgV = $([System.Text.RegularExpressions.Regex]::Match('$([System.IO.File]::ReadAllText($(tpackages)))', 'vsSolutionBuildEvent\" version=\"(.+?)\"').Groups[1].Value))]", + "", + "#[$(demoCore = \"$(demoPath)vsSolutionBuildEvent.$(vssbePkgV).bat\")]", + "#[IO copy.file(\"$(dobj)gnt.bat\", \"$(demoCore)\", true)]", + "", + "#[var demotpl = #[File get(\"demo.vssbe.bat\")]]", + "#[IO replace(\"$(demoCore)\", \"@echo off\", \"$(demotpl.Replace('%v%', $(vssbePkgV)))@echo off\")]", + "", + "", "#[$(shaListDir = $(odir))]", "#[$(searchSubDirs = '1')]", "#[Core events.Post.item(\"ShaList\").run()]" diff --git a/Readme.md b/Readme.md index 086106b..bfb28f3 100644 --- a/Readme.md +++ b/Readme.md @@ -12,7 +12,6 @@ Copyright (c) 2015-2024 Denis Kuzmin github/3F [![Build status](https://ci.appveyor.com/api/projects/status/gw8tij2230gwkqs6/branch/master?svg=true)](https://ci.appveyor.com/project/3Fs/getnutool-github/branch/master) [![release](https://img.shields.io/github/release/3F/GetNuTool.svg)](https://github.com/3F/GetNuTool/releases/latest) -[![Build history](https://buildstats.info/appveyor/chart/3Fs/getnutool-github?buildCount=15&includeBuildsFromPullRequest=true&showStats=true)](https://ci.appveyor.com/project/3Fs/getnutool-github/history) ```bash gnt Fnv1a128 # Get Fnv1a128 package @@ -76,7 +75,7 @@ However! GetNuTool has more powerful ways even for standard NuGet packages provi * Request to the server only if the package is not installed. * Supports proxy with custom credential. * Default settings are overridden through an environment variables: default .config files, NuGet server, etc. -* The ability to create *one click* ~8 KB .bat wrappers for any packages. Try for example [vsSolutionBuildEvent.1.16.bat](https://github.com/3F/GetNuTool/blob/master/demo/wrappers/vsSolutionBuildEvent.1.16.bat) +* The ability to create *one click* ~8 KB .bat wrappers for any packages. Try for example [vsSolutionBuildEvent.bat](https://github.com/3F/GetNuTool/blob/master/demo/vsSolutionBuildEvent.bat) * Easy integration into any scripts such as pure batch-script [netfx4sdk](https://github.com/3F/netfx4sdk), [DllExport](https://github.com/3F/DllExport/wiki/DllExport-Manager), [hMSBuild](https://github.com/3F/hMSBuild) * C# projects support via GetNuTool.cs diff --git a/demo.vssbe.bat b/demo.vssbe.bat new file mode 100644 index 0000000..b656324 --- /dev/null +++ b/demo.vssbe.bat @@ -0,0 +1,3 @@ +@call :GetNuTool vsSolutionBuildEvent/%v% || ( echo Please contact support>&2 & exit /B1 ) +if "%~1"=="" packages\vsSolutionBuildEvent.%v%\GUI +:GetNuTool diff --git a/demo/wrappers/vsSolutionBuildEvent.1.16.bat b/demo/vsSolutionBuildEvent.bat similarity index 75% rename from demo/wrappers/vsSolutionBuildEvent.1.16.bat rename to demo/vsSolutionBuildEvent.bat index 0789068..68cd117 100644 --- a/demo/wrappers/vsSolutionBuildEvent.1.16.bat +++ b/demo/vsSolutionBuildEvent.bat @@ -1,11 +1,11 @@ -@call :GetNuTool vsSolutionBuildEvent/1.16 || ( echo Please contact support >&2 & exit /B 1 ) -packages\vsSolutionBuildEvent.1.16\GUI +@call :GetNuTool vsSolutionBuildEvent || ( echo Please contact support>&2 & exit /B1 ) +if "%~1"=="" packages\vsSolutionBuildEvent\GUI :GetNuTool @echo off -:: GetNuTool /shell/batch edition -:: Copyright (c) 2015-2024 Denis Kuzmin github/3F -:: https://github.com/3F/GetNuTool -set ee=gnt.core&set ef="%temp%\%ee%1.9-RC%random%%random%"&if "%~1"=="-unpack" goto en +::! GetNuTool /shell/batch edition +::! Copyright (c) 2015-2024 Denis Kuzmin github/3F +::! https://github.com/3F/GetNuTool +set ee=gnt.core&set ef="%temp%\%ee%1.9.0%random%%random%"&if "%~1"=="-unpack" goto en if "%~1"=="-msbuild" goto eo set eg=%*&setlocal enableDelayedExpansion&set "eh=%~1 "&set ei=!eh:~0,1!&if "!ei!" NEQ " " if !ei! NEQ / set eg=/p:ngpackages=!eg! set "ej=%msb.gnt.cmd%"&if defined ej goto ep @@ -27,7 +27,7 @@ set ef="%cd%\%ee%"&echo Generating a %ee% at %cd%\... :eq setlocal disableDelayedExpansion %ef%&set -=ngconfig&set [=Condition&set ]=packages.config&set ;=ngserver&set .=package&set ,=GetNuTool&set :=wpath&set +=TaskCoreDllPath&set {=Exists&set }=MSBuildToolsPath&set _=Microsoft.Build.Tasks.&set a=MSBuildToolsVersion&set b=Target&set c=tmode&set d=ParameterGroup&set e=Reference&set f=System&set g=Namespace&set h=Console.WriteLine(&set i=string&set j=return&set k=Console.Error.WriteLine(&set l=string.IsNullOrEmpty(&set m=foreach&set n=Attribute&set o=Append&set p=Path&set q=Combine&set r=Length&set s=false&set t=ToString&set u=SecurityProtocolType&set v=ServicePointManager.SecurityProtocol&set w=Credentials&set x=Directory&set y=CreateDirectory&set z=Console.Write(&set $=using&set #=FileMode&set @=FileAccess&set `=StringComparison&set ?=StartsWith -^^^<%-% %[%="'$(%-%)'==''"^>%]%;.tools\%]%^^<%;% %[%="'$(%;%)'==''"^>https://www.nuget.org/api/v2/%.%/^^packages^^<%,%^>1.9-RC^^<%:% %[%="'$(%:%)'==''"^>$(MSBuildProjectDirectory)^^<%+% %[%="%{%('$(%}%)\%_%v$(%a%).dll')"^>$(%}%)\%_%v$(%a%).dll^^<%+% %[%="'$(%+%)'=='' and %{%('$(%}%)\%_%Core.dll')"^>$(%}%)\%_%Core.dll^^^<%b% Name="get" BeforeTargets="Build"^>^^^<%b% Name="grab"^>^^^<%b% Name="pack"^>^^^^<%d%^>^<%c%/^>^^^<%e% Include="%f%.Xml"/^>^<%e% Include="%f%.Xml.Linq"/^>^<%e% Include="WindowsBase"/^>^^^^^^^^ github/3F\n");var d="{0} is not found ";var e=new %i%[]{"/_rels/","/%.%/","/[Content_Types].xml"};Action^<%i%,object^>f=(g,h)=^>{if("$(debug)".Trim()=="true")%h%g,h);};Func^<%i%,XElement^>i=j=^>{try{%j% XDocument.Load(j).Root;}catch(Exception k){%k%k.Message);throw;}};Func^<%i%,%i%[]^>l=m=^>m.Split(new[]{m.Contains('^|')?'^|':';'},(StringSplitOptions)1);if(%c%=="get"^|^|%c%=="grab"){var n=@"$(ngpackages)";var o=new StringBuilder();if(%l%n)){Action^<%i%^>p=q=^>{%m%(var r in i(q).Descendants("%.%")){var s=r.%n%("id");var t=r.%n%("version");var u=r.%n%("output");var v=r.%n%("sha1");if(s==null){%k%"{0} is corrupted",q);%j%;}o.%o%(s.Value);if(t!=null)o.%o%("/"+t.Value);if(v!=null)o.%o%("?"+v.Value);if(u!=null)o.%o%(":"+u.Value);o.%o%>>%ef% +^^^<%-% %[%="'$(%-%)'==''"^>%]%;.tools\%]%^^<%;% %[%="'$(%;%)'==''"^>https://www.nuget.org/api/v2/%.%/^^packages^^<%,%^>1.9.0^^<%:% %[%="'$(%:%)'==''"^>$(MSBuildProjectDirectory)^^<%+% %[%="%{%('$(%}%)\%_%v$(%a%).dll')"^>$(%}%)\%_%v$(%a%).dll^^<%+% %[%="'$(%+%)'=='' and %{%('$(%}%)\%_%Core.dll')"^>$(%}%)\%_%Core.dll^^^<%b% Name="get" BeforeTargets="Build"^>^^^<%b% Name="grab"^>^^^<%b% Name="pack"^>^^^^<%d%^>^<%c%/^>^^^<%e% Include="%f%.Xml"/^>^<%e% Include="%f%.Xml.Linq"/^>^<%e% Include="WindowsBase"/^>^^^^^^^^ github/3F\n");var d="{0} is not found ";var e=new %i%[]{"/_rels/","/%.%/","/[Content_Types].xml"};Action^<%i%,object^>f=(g,h)=^>{if("$(debug)".Trim()=="true")%h%g,h);};Func^<%i%,XElement^>i=j=^>{try{%j% XDocument.Load(j).Root;}catch(Exception k){%k%k.Message);throw;}};Func^<%i%,%i%[]^>l=m=^>m.Split(new[]{m.Contains('^|')?'^|':';'},(StringSplitOptions)1);if(%c%=="get"^|^|%c%=="grab"){var n=@"$(ngpackages)";var o=new StringBuilder();if(%l%n)){Action^<%i%^>p=q=^>{%m%(var r in i(q).Descendants("%.%")){var s=r.%n%("id");var t=r.%n%("version");var u=r.%n%("output");var v=r.%n%("sha1");if(s==null){%k%"{0} is corrupted",q);%j%;}o.%o%(s.Value);if(t!=null)o.%o%("/"+t.Value);if(v!=null)o.%o%("?"+v.Value);if(u!=null)o.%o%(":"+u.Value);o.%o%>>%ef% ()){try{%v%^|=z;}catch(NotSupportedException){}}if("$(ssl3)"!="true")%v%^&=~(%u%)(48^|192^|768);Func^<%i%,WebProxy^>D=q=^>{var E=q.Split('@');if(E.%r%^<=1)%j% new WebProxy(E[0],%s%);var F=E[0].Split(':');%j% new WebProxy(E[1],%s%){%w%=new NetworkCredential(F[0],F.%r%^>1?F[1]:null)};};Func^<%i%,%i%^>G=H=^>{var I=%p%.GetDirectoryName(H);if(!%x%.%{%(I))%x%.%y%(I);%j% H;};Func^<%i%,%i%,%i%,%i%,bool^>J=(K,L,H,v)=^>{var M=%p%.GetFullPath(%p%.%q%(@"$(%:%)",H??L??""));if(%x%.%{%(M)^|^|File.%{%(M)){%h%"{0} use {1}",L,M);%j% true;}%z%K+" ... ");var N=%c%=="grab";var O=N?G(M):%p%.%q%(%p%.GetTempPath(),Guid.NewGuid().%t%());%$%(var P=new WebClient()){try{if(!%l%y)){P.Proxy=D(y);}P.Headers.Add("User-Agent","%,%/$(%,%)");P.UseDefaultCredentials=true;if(P.Proxy!=null^&^&P.Proxy.%w%==null){P.Proxy.%w%=CredentialCache.DefaultCredentials;}P.DownloadFile(@"$(%;%)"+K,O);}catch(Exception k){%k%k.Message);%j% %s%;}}%h%M);if(v!=null){%z%"{0} ... ",v);%$%(var Q=%f%.Security.Cryptography.SHA1.Create()){o.Clear();%$%(var R=new FileStream(O,(%#%)3,(%@%)1))%m%(var S in Q.ComputeHash(R))o.%o%(S.%t%("x2"));%z%o.%t%());if(!o.%t%().Equals(v,(%`%)5)){%h%"[x]");%j% %s%;}%h%);}}if(N)%j% true;%$%(var r=ZipPackage.Open(O,(%#%)3,(%@%)1)){%m%(var T in r.GetParts()){var U=Uri.UnescapeDataString(T.Uri.OriginalString);if(e.Any(V=^>U.%?%(V,(%`%)4)))continue;var W=%p%.%q%(M,U.TrimStart('/'));f("- {0}",U);%$%(var X=T.GetStream((%#%)3,(%@%)1))%$%(var Y=File.OpenWrite(G(W))){try{X.CopyTo(Y);}catch(FileFormatException){f("[x]?crc: {0}",W);}}}}File.Delete(O);%j% true;};%m%(var r in l(n)){var Z=r.Split(new[]{':'},2);var K=Z[0].Split(new[]{'?'},2);var H=Z.%r%^>1?Z[1]:null;var L=K[0].Replace('/','.');if(!%l%>>%ef% 1?K[1]:null)^&^&"$(break)".Trim()!="no")%j% %s%;}}else if(%c%=="pack"){var a=".nuspec";var b="metadata";var c="id";var A="version";var I=%p%.%q%(@"$(%:%)",@"$(ngin)");if(!%x%.%{%(I)){%k%d,I);%j% %s%;}var B=%x%.GetFiles(I,"*"+a).FirstOrDefault();if(B==null){%k%d+I,a);%j% %s%;}%h%"{0} use {1}",a,B);var C=i(B).Elements().FirstOrDefault(V=^>V.Name.LocalName==b);if(C==null){%k%d,b);%j% %s%;}var _=new %f%.Collections.Generic.Dictionary^<%i%,%i%^>();Func^<%i%,%i%^>dd=de=^>_.ContainsKey(de)?_[de]:"";%m%(var df in C.Elements())_[df.Name.LocalName.ToLower()]=df.Value;if(dd(c).%r%^>100^|^|!%f%.Text.RegularExpressions.Regex.IsMatch(dd(c),@"^\w+(?:[_.-]\w+)*$")){%k%"Invalid id");%j% %s%;}var dg=%i%.Format("{0}.{1}.nupkg",dd(c),dd(A));var dh=%p%.%q%(@"$(%:%)",@"$(ngout)");if(!%i%.IsNullOrWhiteSpace(dh)){if(!%x%.%{%(dh)){%x%.%y%(dh);}dg=%p%.%q%(dh,dg);}%h%"Creating %.% {0} ...",dg);%$%(var r=Package.Open(dg,(%#%)2)){var di=new Uri(%i%.Format("/{0}{1}",dd(c),a),(UriKind)2);r.CreateRelationship(di,0,"http://schemas.microsoft.com/packaging/2010/07/manifest");%m%(var dj in %x%.GetFiles(I,"*.*",(SearchOption)1)){if(e.Any(V=^>dj.%?%(%p%.%q%(I,V.Trim('/')),(%`%)4)))continue;var dk=dj.%?%(I,(%`%)5)?dj.Substring(I.%r%).TrimStart(%p%.DirectorySeparatorChar):dj;f("+ {0}",dk);var T=r.CreatePart(PackUriHelper.CreatePartUri(new Uri(%i%.Join("/",dk.Split('\\','/').Select(Uri.EscapeDataString)),(UriKind)2)),"application/octet",(CompressionOption)1);%$%(var dl=T.GetStream())%$%(var dm=new FileStream(dj,(%#%)3,(%@%)1)){dm.CopyTo(dl);}}var dn=r.PackageProperties;dn.Creator=dd("authors");dn.Description=dd("description");dn.Identifier=dd(c);dn.Version=dd(A);dn.Keywords=dd("tags");dn.Title=dd("title");dn.LastModifiedBy="%,%/$(%,%)";}}else %j% %s%;]]^>^^^^<%b% Name="Build" DependsOnTargets="%,%"/^>^>>%ef% endlocal&exit/B0 diff --git a/vsSolutionBuildEvent.bat b/vsSolutionBuildEvent.bat index fa445c6..88d09b9 100644 --- a/vsSolutionBuildEvent.bat +++ b/vsSolutionBuildEvent.bat @@ -1 +1,2 @@ -@echo off & build # & packages\vsSolutionBuildEvent\GUI \ No newline at end of file +:: Visual Studio IDE plugin: https://github.com/3F/vsSolutionBuildEvent/releases/latest +@.tools\hMSBuild ~x -GetNuTool vsSolutionBuildEvent & if "%~1"=="" packages\vsSolutionBuildEvent\GUI \ No newline at end of file