nuget install creating subfolders - visual-studio

I'm running the following nuget command to extract a dll from a nuget package located in C:\utils and extract it to C:\dll.
nuget.exe install -o C:\dll TDS.AppLogger -source C:\utils
The dll gets extracted to C:\dll\TDS.AppLogger.1.0.0\lib\net452. I'm not sure why it's creating the TDS.AppLogger.1.0.0\lib\net452 subfolders.
Is there an option in the command that I can include which would not create the subfolders?

Is there an option in the command that I can include which would not create the subfolders?
I am afraid not. That because this command is not used to extract a dll from a nuget package, but extract NuGet package from .nupkg files. See Install command for NuGet CLI reference, this command similar to restore in that it only adds packages to disk in a hierarchical layout. And you can check the command about NuGet CLI reference, there is no option in the command to extract a dll from a nuget package.
To resolve this issue, you can consider use a .bat file to extract a dll, below is a sample code:
#echo off
echo Extracting all dlls from nugets to folder C:\dll
REM %mypath% is where the batch file is located
set mypath=%~dp0
set temppath=%~dp0temp\
set dllpath=C:\dll\
mkdir %dllpath%
rem traverse all nupkg files
pushd %mypath%
for /r %%a in (*.nupkg) do (
echo \- Processing %%~nxa
REM unzip nuget to %temppath% folder.
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%%a', '%temppath%'); }
REM Copy all dlls
pushd %temppath%
for /r %%b in (*.dll) do (
echo \- Found %%~nxb
COPY "%%b" "%dllpath%%%~nxb"
)
popd
REM Delete Temp folder
rd /s /q %temppath%"
)
popd
pause
The source code from here.
Just put the bat file under the folder: C:\utils

#Leo-MSFT - Thanks for your response.
I ended up using MSBuild and adding the Unzip task to unzip the nuget package and extract it's contents to a destination location.
<Unzip ZipFileName="$(ReleasePath)\exe\utils\AppLogger.1.0.0.nupkg" TargetDirectory="$(ReleasePath)\exe\dll\" />

Related

nant delete subfolders exclude files

need help regarding delete task in nant or command which can be used in nant build file.
here is the requirement, i have multiple files and folders in a root folder.
i need to delete only folders but not files..
Any idea how to do this.
Blockquote
EX : ROOT
-a.txt
-b.txt
-Folder1
-Folder2
after deletion, it should be
Blockquote
EX: ROOT-
-a.txt
-b.txt
Thanks in advance.
for /d %%a in ("c:\some\root\*") do echo rmdir /s /q "%%~fa"
For each folder inside the indicated path, matching the indicated mask, remove the folder
Delete operations are echoed to console. If the output is correct, remove the echo command to execute the rmdir commands.
To include it in a build file, and avoid problems with quoting, it is better to create a batch file to contain the command and call this batch file. That way, the batch file will be something like
#echo off
if "%~1"=="" exit /b 1
for /d %%a in ("%~1\*") do echo rmdir /s /q "%%~fa"
With the path to the folder to clean passed as argument
Then, the exec task will be something like
<exec program="cmd.exe" commandline="/c theBatchFile.cmd" workingdir="${project.batchFiles}" output="e:\my.txt">
<arg value="${project.rootFolder}" />
</exec>
The variables will need to be defined pointing to
${project.batchFiles} = where the batch file is located
${project.rootFolder} = the folder that needs to be cleaned
So, the task will call cmd.exe to process the batch file, passing the folder as argument to the batch.
used the above suggustions and found it out :
Code :
<echo file="CleanFolders.bat">for /d %%a in ("${dir}\subdir\*") do rmdir /s /q "%%~fa</echo>
<exec program="CleanFolders.bat"/>

7-Zip Command-Line Help (Batch File)

I need to run 7-Zip from a batch file and perform a few tasks, I was wondering if it was possible. Here is my situation:
I have a folder "X:/Archived Backups/" that contains archives and sub-directories with archives.
Some of these archives also contain further archives.
I need to recursively scan the directory and sub-directories and 7-Zip to extract each archive to a folder by the same name (archive name).
I also need it to extract archives within archives within archives etc.
Finally, I need it to delete the archives when extracted (this includes the archives within archives) and only leave the extracted folders.
Is this possible? If so is it possible from the command line? How would I do it?
Many Thanks
:)
Test this to see if it does what you need - it should extract them to x:\extracted\path\filename folders.
It doesn't delete the archives because you have to test this first.
Check the path to 7z.exe first.
#echo off
set "location=x:\extracted"
md "%location%" 2>nul
for /r "X:\Archived Backups" %%a in (*.7z) do (
md "%location%\%%~pna"
pushd "%location%\%%~pna" && ("c:\program files\7-zip\7z.exe" x "%%a" & popd)
)
pause
You can use this post and this as starting points.
For iteration and testing directory:
FOR %%i IN (%VAR%) DO IF EXIST %%~si\NUL ECHO It's a directory
For files, check file extension and extract using 7-zip command :

Visual Studio 2010 Command Prompt - build all solution files

Is there a way to search for all the solution files (.sln) in a given directory, and build them all?
You can do this by using batch or PowerShell to find the fileset and then drive the commandline invocation of the build process.
You can use this batch file:
for /F %%a in ('dir *.sln /s/b') do msbuild "%%a"

How to programatically unzip archives in their own directories on Windows with a DOS command?

There are many ways to unzip archives on Unix:
How do you recursively unzip archives in a directory and its subdirectories from the Unix command-line?
Unzip a bunch of zips into their own directories
The goal is to find all archives and uncompress them in their own directory (where each archive is found) on Windows.
Optional:
remove the archive after unzip.
record any error message if one archive has any issue during unzip.
I am looking for a plain DOS command line, using, for instance, 7z.exe (which is included in the portable version of PeaZip).
I took a command-line from this thread of the sevenzip project, with a small modification:
FOR /R %I IN (*src.zip) DO (C:\apps\peazip_portable-3.8.WINDOWS\res\7z\7z.exe x "%I" -aoa -o"%~dpI\*" |c:\windows\system32\find.exe "Everything is Ok" >nul &&DEL /F "%I" ||ECHO.%I : EXTRACT FAIL - ARC NOT DELETED >>ERR.TXT)
(multi-line for visibility)
FOR /R %I IN (*src.zip) DO ( \
C:\apps\peazip_portable-3.8.WINDOWS\res\7z\7z.exe x "%I" -aoa -o"%~dpI\*"
|c:\windows\system32\find.exe "Everything is Ok" >nul &&DEL /F "%I"
||ECHO.%I : EXTRACT FAIL - ARC NOT DELETED >>ERR.TXT)
Notes:
I prefer specifying "c:\windows\system32\find.exe" instead of just FIND, because I have other 'find.exe' on my PATH (from msysgit, or gow).
remove the '&&DEL /F "%I"' part if you want to keep the archives in place.
I just unzipped 470 "src.zip" from the Rational Team Concert SDK in two minutes with that one-liner!
This is an old question, but somebody may find this useful. This method worked for me using WinZip and the WinZip Command Line add-on, both available on the WinZip site for registered users.
FOR /R %I IN (*.zip) DO (C:\Program Files (x86)\winzip\wzunzip.exe -ye "%I" "%~pI")
-ye will name the folder after zip filename.
%I is the zip file name
%~pI is the zip file contents destination
Feel free to add the debugging messages in the previous answer. Run the command inside the folder where all your subfolders containing your zip files are stored.

How to extract ONLY the contents of the JDK installer

I just downloaded the Java SDK/JDK versions 5 and 6, and I just need the development tools (and some libraries) contained in the installation packages, I don't need to perform an installation and that's why I was only looking for a zip package at first (for Windows there is only an exe installation file), I only need to extract the contents of the installation packages, I think this can be done from the command line but so far I haven't found how to do this (I already considered WinRar and 7-Zip, but I really want to find how to do it without using these tools)
Have you done this before and how?
Here's .bat script for unpacking "pack" files. Must be run in the root of unzipped JDK.
#echo off
echo **********************
echo unpack JDK pack-files
echo **********************
pause
set JAVA_HOME=c:\glassfish4\jdk7
setlocal enableextensions
for /r %%f in (*) do call :process %%f
endlocal
goto :eof
:process
if NOT "%~x1" == ".pack" goto :eof
set FOLDER=%~p1
set PWD=%CD%
pushd %FOLDER%
echo Unpacking %~nx1
%JAVA_HOME%\bin\unpack200.exe %~nx1 %~n1.jar
popd
goto :eof
I use 7-zip to do that. It seems to handle that installer/self-extracting executables nicely.
I've created cygwin script to do that:
https://gist.github.com/4ndrew/f9dca61cedf0e8340b54
#!/bin/sh
# usage example: prepareJdk.sh jdk-7u67-windows-x64.exe (result will be in jdk/)
# Requires: p7zip, unzip
JDK_EXE=$1
7z x -ojdk "$JDK_EXE"
unzip jdk/tools.zip -d jdk/
find jdk/ -type f \( -name "*.exe" -o -name "*.dll" \) -exec chmod u+rwx {} \;
rm jdk/tools.zip
find jdk/ -type f -name "*.pack" | while read eachFile; do
echo "Unpacking $eachFile ...";
./jdk/bin/unpack200.exe $eachFile ${eachFile%.pack}.jar;
rm $eachFile;
done
You can do the installation once and then zip up the installed stuff placed under \Programs\Java.
This can be unzipped elsewhere later and used as a JDK in most IDE's without needing a full reinstall (but then Windows does not know about it)
You can extract both JDK 1.5 and 1.6 from .exe files, using the Universal Extractor (really a great tool). But don't forget to convert all *.pack files (compressed with Pack200 format) into corresponding *.jar files, in order to obtain a full working environment. You can use the unpack200.exe command provided in the JDK itself.
Maybe you can try Universal Extractor. The site looks legit, but I haven't tried it myself.
This is e-egiazarov's script, modified to use unpack200.exe from the JDK archive and also to remove the pack file after conversion.
#echo off
setlocal enableextensions
for /r %%f in (*) do call :process %%f
endlocal
goto :eof
:process
if NOT "%~x1" == ".pack" goto :eof
set FOLDER=%~p1
set PWD=%CD%
pushd %FOLDER%
echo Unpacking %~nx1
%PWD%\bin\unpack200.exe %~nx1 %~n1.jar
del %~nx1
popd
goto :eof
a little late to the party
here's an extractor written in powershell
param($installdir)
$list=$(gci -Recurse ./$installdir/*.pack) | %{
return #{
source=$_.FullName
parent=$_.Directory.FullName
target="$($_.Directory.FullName)\$([io.path]::GetFileNameWithoutExtension($_.Name)).jar"
}
} | %{
$result = $(unpack200 $_.source $_.target)
$_result=$result
return $_
}
Write-Host $(ConvertTo-Json $list)
Being in the folder where it was unzipped by 7zip, the same one that has the bin and lib folders, the command below does the "magic" in Windows, of course. Thanks.
for /f %f in ('dir /s/b *.pack') do bin\unpack200.exe %~pf%~nxf %~pf%~nf.jar

Resources