Skip to content

Commit 35a8e7c

Browse files
authored
Merge pull request #15854 from tamasvajk/buildless/change-assembly-id
C#: Change ID of buildless output assembly
2 parents 42acd9c + 9b5cfc9 commit 35a8e7c

File tree

1 file changed

+21
-7
lines changed
  • csharp/extractor/Semmle.Extraction.CSharp/Entities

1 file changed

+21
-7
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs

+21-7
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ internal class Assembly : Extraction.Entities.Location
99

1010
private readonly string assemblyPath;
1111
private readonly IAssemblySymbol assembly;
12+
private readonly bool isOutputAssembly;
1213

1314
private Assembly(Context cx, Microsoft.CodeAnalysis.Location? init)
1415
: base(cx, init)
1516
{
16-
if (init is null)
17+
isOutputAssembly = init is null;
18+
if (isOutputAssembly)
1719
{
18-
// This is the output assembly
1920
assemblyPath = cx.Extractor.OutputPath;
2021
assembly = cx.Compilation.Assembly;
2122
}
2223
else
2324
{
24-
assembly = init.MetadataModule!.ContainingAssembly;
25+
assembly = init!.MetadataModule!.ContainingAssembly;
2526
var identity = assembly.Identity;
2627
var idString = identity.Name + " " + identity.Version;
2728
assemblyPath = cx.Extractor.GetAssemblyFile(idString);
@@ -32,8 +33,13 @@ public override void Populate(TextWriter trapFile)
3233
{
3334
if (assemblyPath is not null)
3435
{
35-
trapFile.assemblies(this, File.Create(Context, assemblyPath), assembly.ToString() ?? "",
36-
assembly.Identity.Name, assembly.Identity.Version.ToString());
36+
var isBuildlessOutputAssembly = isOutputAssembly && Context.Extractor.Mode.HasFlag(ExtractorMode.Standalone);
37+
var identifier = isBuildlessOutputAssembly
38+
? ""
39+
: assembly.ToString() ?? "";
40+
var name = isBuildlessOutputAssembly ? "" : assembly.Identity.Name;
41+
var version = isBuildlessOutputAssembly ? "" : assembly.Identity.Version.ToString();
42+
trapFile.assemblies(this, File.Create(Context, assemblyPath), identifier, name, version);
3743
}
3844
}
3945

@@ -68,8 +74,16 @@ public static Assembly CreateOutputAssembly(Context cx)
6874

6975
public override void WriteId(EscapingTextWriter trapFile)
7076
{
71-
trapFile.Write(assembly.ToString());
72-
if (!(assemblyPath is null))
77+
if (isOutputAssembly && Context.Extractor.Mode.HasFlag(ExtractorMode.Standalone))
78+
{
79+
trapFile.Write("buildlessOutputAssembly");
80+
}
81+
else
82+
{
83+
trapFile.Write(assembly.ToString());
84+
}
85+
86+
if (assemblyPath is not null)
7387
{
7488
trapFile.Write("#file:///");
7589
trapFile.Write(assemblyPath.Replace("\\", "/"));

0 commit comments

Comments
 (0)