Skip to content

Commit 73ad417

Browse files
authored
Merge pull request #5132 from tamasvajk/feature/dotnet502
C#: Upgrade projects to .net 5
2 parents 8e2af07 + 714e1dc commit 73ad417

File tree

46 files changed

+1010
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1010
-384
lines changed

cpp/autobuilder/Semmle.Autobuild.Cpp.Tests/Semmle.Autobuild.Cpp.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
77
<RuntimeIdentifiers>win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
88
<Nullable>enable</Nullable>

cpp/autobuilder/Semmle.Autobuild.Cpp/Semmle.Autobuild.Cpp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<AssemblyName>Semmle.Autobuild.Cpp</AssemblyName>
66
<RootNamespace>Semmle.Autobuild.Cpp</RootNamespace>
77
<ApplicationIcon />

csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/Semmle.Autobuild.CSharp.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
77
<RuntimeIdentifiers>win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
88
<Nullable>enable</Nullable>

csharp/autobuilder/Semmle.Autobuild.CSharp/Semmle.Autobuild.CSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<AssemblyName>Semmle.Autobuild.CSharp</AssemblyName>
66
<RootNamespace>Semmle.Autobuild.CSharp</RootNamespace>
77
<ApplicationIcon />

csharp/autobuilder/Semmle.Autobuild.Shared/BuildActions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ int IBuildActions.RunProcess(string cmd, string args, string? workingDirectory,
170170
{
171171
var pi = GetProcessStartInfo(cmd, args, workingDirectory, environment, false);
172172
using var p = Process.Start(pi);
173+
if (p is null)
174+
{
175+
return -1;
176+
}
173177
p.WaitForExit();
174178
return p.ExitCode;
175179
}

csharp/autobuilder/Semmle.Autobuild.Shared/BuildTools.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ public static IEnumerable<VcVarsBatFile> VcVarsAllBatFiles(IBuildActions actions
8484
/// </summary>
8585
/// <param name="sln">The solution file.</param>
8686
/// <returns>A compatible file, or throws an exception.</returns>
87-
public static VcVarsBatFile FindCompatibleVcVars(IBuildActions actions, ISolution sln) =>
87+
public static VcVarsBatFile? FindCompatibleVcVars(IBuildActions actions, ISolution sln) =>
8888
FindCompatibleVcVars(actions, sln.ToolsVersion.Major);
8989

9090
/// <summary>
9191
/// Finds a VcVars that provides a compatible environment for the given tools version.
9292
/// </summary>
9393
/// <param name="targetVersion">The tools version.</param>
9494
/// <returns>A compatible file, or null.</returns>
95-
public static VcVarsBatFile FindCompatibleVcVars(IBuildActions actions, int targetVersion) =>
96-
targetVersion < 10 ?
97-
VcVarsAllBatFiles(actions).OrderByDescending(b => b.ToolsVersion).FirstOrDefault() :
98-
VcVarsAllBatFiles(actions).Where(b => b.ToolsVersion >= targetVersion).OrderBy(b => b.ToolsVersion).FirstOrDefault();
95+
public static VcVarsBatFile? FindCompatibleVcVars(IBuildActions actions, int targetVersion) =>
96+
targetVersion < 10
97+
? VcVarsAllBatFiles(actions).OrderByDescending(b => b.ToolsVersion).FirstOrDefault()
98+
: VcVarsAllBatFiles(actions).Where(b => b.ToolsVersion >= targetVersion).OrderBy(b => b.ToolsVersion).FirstOrDefault();
9999
}
100100
}

csharp/autobuilder/Semmle.Autobuild.Shared/Project.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Project(Autobuilder builder, string path) : base(builder, path)
4747

4848
var root = projFile.DocumentElement;
4949

50-
if (root.Name == "Project")
50+
if (root?.Name == "Project")
5151
{
5252
if (root.HasAttribute("Sdk"))
5353
{
@@ -77,10 +77,17 @@ public Project(Autobuilder builder, string path) : base(builder, path)
7777
// `<ProjectFile Include="X"/>` and `<ProjectFiles Include="X"/>` is valid
7878
var mgr = new XmlNamespaceManager(projFile.NameTable);
7979
mgr.AddNamespace("msbuild", "http://schemas.microsoft.com/developer/msbuild/2003");
80-
var projectFileIncludes = root.SelectNodes("//msbuild:Project/msbuild:ItemGroup/msbuild:ProjectFile/@Include", mgr).OfType<XmlNode>();
81-
var projectFilesIncludes = root.SelectNodes("//msbuild:Project/msbuild:ItemGroup/msbuild:ProjectFiles/@Include", mgr).OfType<XmlNode>();
80+
var projectFileIncludes = root.SelectNodes("//msbuild:Project/msbuild:ItemGroup/msbuild:ProjectFile/@Include", mgr)
81+
?.OfType<XmlNode>() ?? Array.Empty<XmlNode>();
82+
var projectFilesIncludes = root.SelectNodes("//msbuild:Project/msbuild:ItemGroup/msbuild:ProjectFiles/@Include", mgr)
83+
?.OfType<XmlNode>() ?? Array.Empty<XmlNode>();
8284
foreach (var include in projectFileIncludes.Concat(projectFilesIncludes))
8385
{
86+
if (include?.Value is null)
87+
{
88+
continue;
89+
}
90+
8491
var includePath = builder.Actions.PathCombine(include.Value.Split('\\', StringSplitOptions.RemoveEmptyEntries));
8592
ret.Add(new Project(builder, builder.Actions.PathCombine(DirectoryName, includePath)));
8693
}

csharp/autobuilder/Semmle.Autobuild.Shared/Semmle.Autobuild.Shared.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<AssemblyName>Semmle.Autobuild.Shared</AssemblyName>
66
<RootNamespace>Semmle.Autobuild.Shared</RootNamespace>
77
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>

csharp/autobuilder/Semmle.Autobuild.Shared/Solution.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public Solution(Autobuilder builder, string path, bool allowProject) : base(buil
9090
.Select(p => p.ToolsVersion);
9191

9292
public Version ToolsVersion => ToolsVersions.Any()
93-
? ToolsVersions.Max()
93+
? ToolsVersions.Max()!
9494
: new Version();
9595
}
9696
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* The extractor has been updated to use dotnet 5 dependencies.

0 commit comments

Comments
 (0)