Skip to content

Commit

Permalink
Converting to dotnet tool (#306)
Browse files Browse the repository at this point in the history
* Converting to dotnet tool

* adding changelog fixing signing dlls

* updating changelog

* adding unreleased tag

* updating release history
  • Loading branch information
eddynaka committed Nov 24, 2020
1 parent 2e55eae commit c5ad18a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 52 deletions.
33 changes: 10 additions & 23 deletions BuildAndTest.cmd
Expand Up @@ -37,48 +37,35 @@ echo public const string Version = AssemblyVersion + Prerelease;
echo } >> %VERSION_CONSTANTS%
echo } >> %VERSION_CONSTANTS%

::Restore packages
:: Restore packages
echo Restoring packages...
dotnet restore %~dp0src\BinSkim.sln /p:Configuration=%Configuration% --configfile "%NuGetConfigFile%" --packages "%NuGetPackageDir%

:: Build the solution
echo Building solution...
dotnet build --no-restore /verbosity:minimal %~dp0src\BinSkim.sln /p:Configuration=%Configuration% /filelogger /fileloggerparameters:Verbosity=detailed || goto :ExitFailed

::Run unit tests
echo Run all multitargeting xunit tests
call :RunTestProject BinaryParsers Unit || goto :ExitFailed
call :RunTestProject BinSkim.Rules Unit || goto :ExitFailed
call :RunTestProject BinSkim.Driver Functional || goto :ExitFailed
call :RunTestProject BinSkim.Rules Functional || goto :ExitFailed
:: Run unit tests
echo Running tests...
dotnet test %~dp0src\BinSkim.sln /p:Configuration=%Configuration% --no-build

::Create the BinSkim platform specific publish packages
echo Creating Platform Specific BinSkim 'Publish' Packages
call :CreatePublishPackage netcoreapp3.1 win-x86 || goto :ExitFailed
call :CreatePublishPackage netcoreapp3.1 win-x64 || goto :ExitFailed
call :CreatePublishPackage netcoreapp3.1 linux-x64 || goto :ExitFailed
:: Create the BinSkim publish packages
echo Creating Platform 'Publish' Packages...
call :CreatePublishPackage netcoreapp3.1 || goto :ExitFailed

::Build NuGet package
:: Build NuGet package
echo BuildPackages.cmd
call BuildPackages.cmd || goto :ExitFailed

::Create layout directory of assemblies that need to be signed
:: Create layout directory of assemblies that need to be signed
echo CreateLayoutDirectory.cmd %~dp0bld\bin %Configuration% %Platform%
call CreateLayoutDirectory.cmd %~dp0bld\bin %Configuration% %Platform%

goto :Exit

:RunTestProject
set TestProject=%1
set TestType=%2
pushd %~dp0src\Test.%TestType%Tests.%TestProject% && dotnet test --no-build -c %Configuration% && popd
if "%ERRORLEVEL%" NEQ "0" (echo %TestProject% %TestType% tests execution FAILED.)
Exit /B %ERRORLEVEL%

:CreatePublishPackage
set Framework=%~1
set RuntimeArg=%~2
dotnet publish %~dp0src\BinSkim.Driver\BinSkim.Driver.csproj --no-restore -c %Configuration% -f %Framework% --runtime %RuntimeArg%
dotnet publish %~dp0src\BinSkim.Driver\BinSkim.Driver.csproj --no-restore -c %Configuration% -f %Framework%
Exit /B %ERRORLEVEL%

:ExitFailed
Expand Down
2 changes: 1 addition & 1 deletion BuildPackages.cmd
Expand Up @@ -4,7 +4,7 @@ SETLOCAL

call SetCurrentVersion.cmd

%~dp0.nuget\NuGet.exe pack %~dp0src\Nuget\BinSkim.nuspec -Symbols -Properties configuration=%Configuration%;version=%MAJOR%.%MINOR%.%PATCH%%PRERELEASE% -Verbosity Quiet -BasePath %~dp0 -OutputDirectory %~dp0bld\bin\Nuget || goto :ExitFailed
%~dp0.nuget\NuGet.exe pack %~dp0src\Nuget\BinSkim.nuspec -Properties configuration=%Configuration%;version=%MAJOR%.%MINOR%.%PATCH%%PRERELEASE% -Verbosity Quiet -BasePath %~dp0 -OutputDirectory %~dp0bld\bin\Nuget || goto :ExitFailed

goto Exit

Expand Down
13 changes: 2 additions & 11 deletions CreateLayoutDirectory.cmd
Expand Up @@ -23,9 +23,6 @@ set LayoutForSigningDirectory=%BinaryOutputDirectory%\..\LayoutForSigning

call :CreateDirIfNotExist %LayoutForSigningDirectory%
call :CreateDirIfNotExist %LayoutForSigningDirectory%\netcoreapp3.1
call :CreateDirIfNotExist %LayoutForSigningDirectory%\netcoreapp3.1\win-x86\
call :CreateDirIfNotExist %LayoutForSigningDirectory%\netcoreapp3.1\win-x64\
call :CreateDirIfNotExist %LayoutForSigningDirectory%\netcoreapp3.1\linux-x64\

call :CopyExeForSigning BinSkim.exe || goto :ExitFailed
call :CopyFilesForMultitargeting BinSkim.dll || goto :ExitFailed
Expand All @@ -36,19 +33,13 @@ call :CopyFilesForMultitargeting BinSkim.Sdk.dll || goto :ExitFailed
goto :Exit

:CopyExeForSigning
xcopy /Y %BinaryOutputDirectory%\netcoreapp3.1\win-x86\%~n1.exe %LayoutForSigningDirectory%\netcoreapp3.1\win-x86\
if "%ERRORLEVEL%" NEQ "0" (echo %1 assembly copy failed. && goto :ExeFilesExit)
xcopy /Y %BinaryOutputDirectory%\netcoreapp3.1\win-x64\%~n1.exe %LayoutForSigningDirectory%\netcoreapp3.1\win-x64\
xcopy /Y %BinaryOutputDirectory%\netcoreapp3.1\%~n1.exe %LayoutForSigningDirectory%\netcoreapp3.1\
if "%ERRORLEVEL%" NEQ "0" (echo %1 assembly copy failed. && goto :ExeFilesExit)
:ExeFilesExit
Exit /B %ERRORLEVEL%

:CopyFilesForMultitargeting
xcopy /Y %BinaryOutputDirectory%\netcoreapp3.1\win-x86\%~n1.dll %LayoutForSigningDirectory%\netcoreapp3.1\win-x86\
if "%ERRORLEVEL%" NEQ "0" (echo %1 assembly copy failed. && goto :CopyFilesExit)
xcopy /Y %BinaryOutputDirectory%\netcoreapp3.1\win-x64\%~n1.dll %LayoutForSigningDirectory%\netcoreapp3.1\win-x64\
if "%ERRORLEVEL%" NEQ "0" (echo %1 assembly copy failed. && goto :CopyFilesExit)
xcopy /Y %BinaryOutputDirectory%\netcoreapp3.1\linux-x64\%~n1.dll %LayoutForSigningDirectory%\netcoreapp3.1\linux-x64\
xcopy /Y %BinaryOutputDirectory%\netcoreapp3.1\%~n1.dll %LayoutForSigningDirectory%\netcoreapp3.1\
if "%ERRORLEVEL%" NEQ "0" (echo %1 assembly copy failed. && goto :CopyFilesExit)
:CopyFilesExit
Exit /B %ERRORLEVEL%
Expand Down
10 changes: 2 additions & 8 deletions CreatePackagesFromLayoutDirectory.cmd
Expand Up @@ -36,19 +36,13 @@ call BuildPackages.cmd %Configuration% %Platform% %NuGetOutputDirectory% %Versio
goto :Exit

:CopyExeForSigning
xcopy /Y %LayoutForSigningDirectory%\netcoreapp3.1\win-x86\%~n1.exe %BinaryOutputDirectory%\netcoreapp3.1\win-x86\
if "%ERRORLEVEL%" NEQ "0" (echo %1 assembly copy failed. && goto :ExeFilesExit)
xcopy /Y %LayoutForSigningDirectory%\netcoreapp3.1\win-x64\%~n1.exe %BinaryOutputDirectory%\netcoreapp3.1\win-x64\
xcopy /Y %LayoutForSigningDirectory%\netcoreapp3.1\%~n1.exe %BinaryOutputDirectory%\netcoreapp3.1\
if "%ERRORLEVEL%" NEQ "0" (echo %1 assembly copy failed. && goto :ExeFilesExit)
:ExeFilesExit
Exit /B %ERRORLEVEL%

:CopyFilesForMultitargeting
xcopy /Y %BinaryOutputDirectory%\netcoreapp3.1\win-x86\%~n1.dll %LayoutForSigningDirectory%\netcoreapp3.1\win-x86\
if "%ERRORLEVEL%" NEQ "0" (echo %1 assembly copy failed. && goto :CopyFilesExit)
xcopy /Y %BinaryOutputDirectory%\netcoreapp3.1\win-x64\%~n1.dll %LayoutForSigningDirectory%\netcoreapp3.1\win-x64\
if "%ERRORLEVEL%" NEQ "0" (echo %1 assembly copy failed. && goto :CopyFilesExit)
xcopy /Y %BinaryOutputDirectory%\netcoreapp3.1\linux-x64\%~n1.dll %LayoutForSigningDirectory%\netcoreapp3.1\linux-x64\
xcopy /Y %LayoutForSigningDirectory%\netcoreapp3.1\%~n1.dll %BinaryOutputDirectory%\netcoreapp3.1\
if "%ERRORLEVEL%" NEQ "0" (echo %1 assembly copy failed. && goto :CopyFilesExit)
:CopyFilesExit
Exit /B %ERRORLEVEL%
Expand Down
18 changes: 11 additions & 7 deletions src/BinSkim.Driver/BinSkim.Driver.csproj
Expand Up @@ -9,19 +9,23 @@
<TargetLatestRuntimePatch>True</TargetLatestRuntimePatch>
<OutputType>Exe</OutputType>
</PropertyGroup>

<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<RootNamespace>Microsoft.CodeAnalysis.IL</RootNamespace>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Microsoft/binskim</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<Content Include="README.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include=".\DotnetToolSettings.xml" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.7.82" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.6.1" />
Expand All @@ -31,28 +35,28 @@
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
<PackageReference Include="System.Reflection.Metadata" Version="1.5.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="dia2lib">
<HintPath>..\..\refs\dia2lib.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BinaryParsers\BinaryParsers.csproj" />
<ProjectReference Include="..\BinSkim.Rules\BinSkim.Rules.csproj" />
<ProjectReference Include="..\BinSkim.Sdk\BinSkim.Sdk.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="DriverResources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>DriverResources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="DriverResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
6 changes: 6 additions & 0 deletions src/BinSkim.Driver/DotnetToolSettings.xml
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<DotNetCliTool Version="1">
<Commands>
<Command Name="binskim" EntryPoint="BinSkim.dll" Runner="dotnet" />
</Commands>
</DotNetCliTool>
5 changes: 4 additions & 1 deletion src/Nuget/BinSkim.nuspec
Expand Up @@ -15,9 +15,12 @@
<projectUrl>https://github.com/microsoft/binskim</projectUrl>
<tags>binary analysis binskim binscope security portable executable linkable format sdl devops devsecops</tags>
<iconUrl>https://go.microsoft.com/fwlink/?linkid=2008940</iconUrl>
<packageTypes>
<packageType name="DotnetTool" />
</packageTypes>
</metadata>
<files>
<file src="bld\bin\AnyCPU_$configuration$\Publish\**\*" target="tools"/>
<file src="bld\bin\AnyCPU_$configuration$\Publish\netcoreapp3.1\**\*" target="tools\netcoreapp3.1\any"/>
<file src="src\ReleaseHistory.md" target="tools\ReleaseHistory.md" />
<file src="src\BinaryParsers\**\*.cs" target="src\BinaryParsers" />
<file src="src\BinSkim.Driver\**\*.cs" target="src\BinSkim.Driver" />
Expand Down
6 changes: 5 additions & 1 deletion src/ReleaseHistory.md
@@ -1,9 +1,13 @@
# BinSkim Release History

## **Unreleased**

* **BREAKING** Change from self-contained to dotnettool. [#306](https://github.com/microsoft/binskim/pull/306)

## **v1.7.0** [NuGet Package](https://www.nuget.org/packages/Microsoft.CodeAnalysis.BinSkim/1.7.0)
* **AUTOMATION BREAKING**: Update to .NET Core 3.1. Changes tool paths in NuGet package.
* **FEATURE**: Add `--trace` argument to enable specialized trace of execution behavior, such as `PdbLoad`.
* Update SARIF version to 2.2.3
* **FEATURE**: Update SARIF version to 2.3.8
* **BREAKING** Default output is sarif v2

## **v1.6.1** [NuGet Package](https://www.nuget.org/packages/Microsoft.CodeAnalysis.BinSkim/1.6.1)
Expand Down

0 comments on commit c5ad18a

Please sign in to comment.