Skip to content

Commit

Permalink
Build for Net 7.0 (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfs authored Nov 16, 2022
1 parent f869820 commit 9e86ced
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.x'
dotnet-version: '7.x'
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
Expand Down
52 changes: 43 additions & 9 deletions Cli/AttackSurfaceAnalyzerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,48 @@ private static void SetupOrDie(string path, DBSettings? dbSettingsIn = null)
Environment.Exit((int)errorCode);
}
}

private static ASA_ERROR RunGuiCommand(GuiCommandOptions opts)
{
var server = Host.CreateDefaultBuilder(Array.Empty<string>())
#if RELEASE
.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
#endif
.ConfigureWebHostDefaults(webBuilder =>
IHostBuilder server = Host.CreateDefaultBuilder(Array.Empty<string>());
var assemblyLocation = Directory.GetParent(Assembly.GetExecutingAssembly().Location)?.FullName;
if (assemblyLocation is null)
{
Log.Error("Couldn't get directory containing assembly, unable to set content root.");
return ASA_ERROR.FAILED_TO_LOCATE_GUI_ASSETS;
}

// We have to set the content root to the folder with the assemblies to function properly
server.UseContentRoot(assemblyLocation);

// If we are running from debug or from a dotnet publish the wwwroot will be adjacent to the assemblies
var wwwrootLocation = Path.Combine(assemblyLocation, "wwwroot");
var webRoot = wwwrootLocation;

// If the expected wwwroot doesn't exist, we can also check if we are installed as a dotnet tool
if (!Directory.Exists(wwwrootLocation))
{
// If we are installed as a tool the assembly will be located in a folder structure that looks like this
// <toolname>\<version>\tools\<framework>\<platform>\
// The wwwroot is in a folder called "staticwebassets" in the <version> folder, so we want to go 3 levels up.
var toolRootInstallDirectory = new DirectoryInfo(assemblyLocation)?.Parent?.Parent?.Parent;
if (toolRootInstallDirectory is { })
{
var staticWebAssetsLocation = Path.Combine(toolRootInstallDirectory.FullName, "staticwebassets");
if (Directory.Exists(staticWebAssetsLocation))
{
webRoot = staticWebAssetsLocation;
}
else
{
Log.Warning("Could not find static web assets. GUI likely will not load properly");
}
}
}

var host = server.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseWebRoot(webRoot);
webBuilder.UseStartup<Startup>();
})
.Build();
Expand All @@ -452,8 +485,9 @@ private static ASA_ERROR RunGuiCommand(GuiCommandOptions opts)
}))();
}

server.Run();
return 0;
host.Run();

return ASA_ERROR.NONE;
}

private static void SleepAndOpenBrowser(int sleep)
Expand Down Expand Up @@ -1252,7 +1286,7 @@ void PopulateAnalysisForResult(CompareResult res)
// checking rules which don't apply
var selectedRules = platformRules.Where((rule) =>
(rule.ChangeTypes == null || rule.ChangeTypes.Contains(res.ChangeType))
&& (rule.ResultType == res.ResultType));
&& (rule.ResultType == res.ResultType)).ToList();
if (res is null)
{
return;
Expand Down
6 changes: 3 additions & 3 deletions Cli/Cli.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<OutputType>Exe</OutputType>
<ReleaseVersion>0.0.0-placeholder</ReleaseVersion>
Expand All @@ -23,6 +22,7 @@
<ToolCommandName>asa</ToolCommandName>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageIcon>icon-128.png</PackageIcon>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -37,8 +37,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" />
<PackageReference Include="Microsoft.CST.OAT.Blazor.Components" Version="1.2.36" />
<PackageReference Include="Microsoft.CST.OAT.Scripting" Version="1.2.36" />
<PackageReference Include="Microsoft.CST.OAT.Blazor.Components" Version="1.2.38" />
<PackageReference Include="Microsoft.CST.OAT.Scripting" Version="1.2.38" />
<PackageReference Include="Sarif.Sdk" Version="3.1.0" />
<PackageReference Include="Tewr.Blazor.FileReader" Version="3.3.1.21360" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"ASA GUI": {
"commandName": "Project",
"commandLineArgs": "gui",
"commandLineArgs": "gui --nolaunch",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
1 change: 0 additions & 1 deletion Lib/Collectors/BaseCompare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Linq;
using System.Reflection;
using Tpm2Lib;
using System.Diagnostics;

namespace Microsoft.CST.AttackSurfaceAnalyzer.Collectors
{
Expand Down
19 changes: 9 additions & 10 deletions Lib/Lib.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<RootNamespace>AttackSurfaceAnalyzer</RootNamespace>
<LangVersion>10.0</LangVersion>
Expand All @@ -22,6 +21,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<ReleaseVersion>2.1-alpha</ReleaseVersion>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<Target Name="CopyLicenseNotice" AfterTargets="AfterBuild">
Expand All @@ -37,25 +37,24 @@
<PackageReference Include="MedallionShell" Version="1.6.2" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" />
<PackageReference Include="Microsoft.CST.OAT" Version="1.2.36" />
<PackageReference Include="Microsoft.CST.RecursiveExtractor" Version="1.1.18" />
<PackageReference Include="Microsoft.CST.OAT" Version="1.2.38" />
<PackageReference Include="Microsoft.CST.RecursiveExtractor" Version="1.1.19" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.10" />
<PackageReference Include="Microsoft.PowerShell.Commands.Diagnostics" Version="7.2.7" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.7" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />
<PackageReference Include="System.Management" Version="6.0.0" />
<PackageReference Include="System.Management" Version="7.0.0" />
<PackageReference Include="System.Net.NetworkInformation" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
<PackageReference Include="Microsoft.Win32.Registry.AccessControl" Version="6.0.0" />
<PackageReference Include="Microsoft.Win32.Registry.AccessControl" Version="7.0.0" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
<PackageReference Include="System.Security.AccessControl" Version="6.0.0" />
<PackageReference Include="System.Threading.AccessControl" Version="6.0.0" />
<PackageReference Include="System.Threading.AccessControl" Version="7.0.0" />
<PackageReference Include="System.Net.Security" Version="4.3.2" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageReference Include="WindowsFirewallHelper" Version="2.2.0.86" />
Expand Down
3 changes: 2 additions & 1 deletion Lib/Objects/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public enum ASA_ERROR
UNKNOWN,
CANCELLED,
FAILED_TO_COMMIT,
DATABASE_NULL
DATABASE_NULL,
FAILED_TO_LOCATE_GUI_ASSETS
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions Lib/Utils/SqliteDatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.CST.AttackSurfaceAnalyzer.Collectors;
using Microsoft.CST.AttackSurfaceAnalyzer.Objects;
using Microsoft.CST.AttackSurfaceAnalyzer.Types;
using Microsoft.CST.OAT.Operations;
using Microsoft.Data.Sqlite;
using Newtonsoft.Json;
using Serilog;
Expand All @@ -14,7 +13,6 @@
using System.Linq;
using System.Reflection;
using System.Threading;
using Namotion.Reflection;

namespace Microsoft.CST.AttackSurfaceAnalyzer.Utils
{
Expand Down
21 changes: 20 additions & 1 deletion Pipelines/core-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ variables:
value: ASA_Cli
- name: AsaLibName
value: ASA_Lib
- name: CurrentSDK
value: 7.0.x
- name: CurrentFramework
value: net7.0
- name: LTS_SDK
value: 6.0.x
- name: LTS_Framework
value: net6.0

name: ASA_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
trigger:
Expand Down Expand Up @@ -37,6 +45,9 @@ stages:
jobs:
- template: templates/dotnet-test-job.yml
parameters:
jobName: 'test'
dotnetVersion: '${{ variables.CurrentSDK }}'
dotnetVersionLTS: '${{ variables.LTS_SDK }}'
projectPath: 'Tests/Tests.csproj'

- stage: SDL
Expand All @@ -52,24 +63,32 @@ stages:
parameters:
projectPath: 'Cli/Cli.csproj'
projectName: 'ASA'
dotnetVersion: '${{ variables.CurrentSDK }}'
publishFrameworkVersion: '${{ variables.CurrentFramework }}'
preBuild:
- template: templates/nbgv-set-version-steps.yml
- template: templates/dotnet-publish-win-netcore-job.yml
parameters:
projectPath: 'Cli/Cli.csproj'
projectName: 'ASA'
dotnetVersion: '${{ variables.CurrentSDK }}'
publishFrameworkVersion: '${{ variables.CurrentFramework }}'
preBuild:
- template: templates/nbgv-set-version-steps.yml
- template: templates/nuget-build-job.yml
parameters:
jobName: 'pack_lib'
projectPath: 'Lib/Lib.csproj'
projectName: '${{ variables.AsaLibName }}'
dotnetVersion: '${{ variables.CurrentSDK }}'
dotnetVersionLTS: '${{ variables.LTS_SDK }}'
- template: templates/nuget-build-job.yml
parameters:
jobName: 'pack_cli'
projectPath: 'Cli/Cli.csproj'
projectName: '${{ variables.AsaClientName }}'
dotnetVersion: '${{ variables.CurrentSDK }}'
dotnetVersionLTS: '${{ variables.LTS_SDK }}'

- stage: Release
dependsOn:
Expand All @@ -85,7 +104,7 @@ stages:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
version: '${{ variables.CurrentSDK }}'
- script: 'dotnet tool update -g nbgv'
displayName: 'Install GitVersioning'
- task: PowerShell@2
Expand Down
10 changes: 7 additions & 3 deletions Pipelines/templates/dotnet-publish-linux-mac-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ parameters:
# Version of Dotnet SDK to use
- name: dotnetVersion
type: string
default: '6.x'
default: '6.0.x'
# Version of Dotnet SDK to use
- name: publishFrameworkVersion
type: string
default: 'net6.0'
# Version of NuGet Tool to use
- name: nugetVersion
type: string
Expand Down Expand Up @@ -62,14 +66,14 @@ jobs:
displayName: Publish Linux x64
inputs:
command: 'publish'
arguments: '${{ parameters.projectPath }} -c ${{ parameters.buildConfiguration }} -o bin/linux/${{ parameters.projectName }}_linux_$(ReleaseVersion) -r linux-x64'
arguments: '${{ parameters.projectPath }} -f ${{ parameters.publishFrameworkVersion}} -c ${{ parameters.buildConfiguration }} -o bin/linux/${{ parameters.projectName }}_linux_$(ReleaseVersion) -r linux-x64'
publishWebProjects: false
zipAfterPublish: false
- task: DotNetCoreCLI@2
displayName: Publish MacOS x64
inputs:
command: 'publish'
arguments: '${{ parameters.projectPath }} -c ${{ parameters.buildConfiguration }} -o bin/macos/${{ parameters.projectName }}_macos_$(ReleaseVersion) -r osx-x64'
arguments: '${{ parameters.projectPath }} -f ${{ parameters.publishFrameworkVersion}} -c ${{ parameters.buildConfiguration }} -o bin/macos/${{ parameters.projectName }}_macos_$(ReleaseVersion) -r osx-x64'
publishWebProjects: false
zipAfterPublish: false
- task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0
Expand Down
10 changes: 7 additions & 3 deletions Pipelines/templates/dotnet-publish-win-netcore-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ parameters:
# Version of Dotnet SDK to use
- name: dotnetVersion
type: string
default: '6.x'
default: '6.0.x'
# Version of Dotnet SDK to use
- name: publishFrameworkVersion
type: string
default: 'net6.0'
# Version of NuGet Tool to use
- name: nugetVersion
type: string
Expand Down Expand Up @@ -62,14 +66,14 @@ jobs:
displayName: Publish Win x64
inputs:
command: 'publish'
arguments: '${{ parameters.projectPath }} -c ${{ parameters.buildConfiguration }} -o bin/win/${{ parameters.projectName }}_win_$(ReleaseVersion) -r win-x64'
arguments: '${{ parameters.projectPath }} -f ${{ parameters.publishFrameworkVersion}} -c ${{ parameters.buildConfiguration }} -o bin/win/${{ parameters.projectName }}_win_$(ReleaseVersion) -r win-x64'
publishWebProjects: false
zipAfterPublish: false
- task: DotNetCoreCLI@2
displayName: Build .NET Core App
inputs:
command: 'publish'
arguments: '${{ parameters.projectPath }} -c ${{ parameters.buildConfiguration }} -o bin/netcoreapp/${{ parameters.projectName }}_netcoreapp_$(ReleaseVersion)'
arguments: '${{ parameters.projectPath }} -f ${{ parameters.publishFrameworkVersion}} -c ${{ parameters.buildConfiguration }} -o bin/netcoreapp/${{ parameters.projectName }}_netcoreapp_$(ReleaseVersion)'
publishWebProjects: false
zipAfterPublish: false
- task: AntiMalware@3
Expand Down
19 changes: 9 additions & 10 deletions Pipelines/templates/dotnet-test-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ parameters:
# Version of Dotnet SDK to use
- name: dotnetVersion
type: string
default: '6.x'
default: '7.0.x'
# Version of Dotnet SDK to use
- name: dotnetVersionLTS
type: string
default: '6.0.x'
# Version of NuGet Tool to use
- name: nugetVersion
type: string
Expand All @@ -27,16 +31,11 @@ jobs:
inputs:
packageType: 'sdk'
version: ${{ parameters.dotnetVersion }}
- task: NuGetToolInstaller@1
displayName: Install Nuget Tool
inputs:
versionSpec: ${{ parameters.nugetVersion }}
- task: DotNetCoreCLI@2
displayName: Dotnet Restore
- task: UseDotNet@2
displayName: Install Dotnet SDK
inputs:
command: 'restore'
projects: ${{ parameters.projectPath }}
verbosityRestore: 'Normal'
packageType: 'sdk'
version: ${{ parameters.dotnetVersionLTS }}
- task: DotNetCoreCLI@2
displayName: Dotnet Test
inputs:
Expand Down
6 changes: 5 additions & 1 deletion Pipelines/templates/nuget-build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ parameters:
# Version of Dotnet SDK to use
- name: dotnetVersion
type: string
default: '6.x'
default: '7.0.x'
# Version of Dotnet SDK to use
- name: dotnetVersionLTS
type: string
default: '6.0.x'
# Version of NuGet Tool to use
- name: nugetVersion
type: string
Expand Down
4 changes: 2 additions & 2 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<IsPackable>false</IsPackable>
<AssemblyName>AsaTests</AssemblyName>
<ReleaseVersion>0.0.0-placeholder</ReleaseVersion>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
</ItemGroup>
Expand Down

0 comments on commit 9e86ced

Please sign in to comment.