Skip to content

Commit 40132eb

Browse files
authored
Improve RID checking (#105)
* Require RID for self-contained publishing; remove RID inference logic. * Review log traces
1 parent 711988e commit 40132eb

File tree

1 file changed

+13
-51
lines changed

1 file changed

+13
-51
lines changed

src/DotnetPackaging/Publish/DotnetPublisher.cs

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ public async Task<Result<PublishResult>> Publish(ProjectPublishRequest request)
3232
{
3333
logger.Information("Preparing to publish project {ProjectPath}", request.ProjectPath);
3434

35+
// Validate that RID is provided when SelfContained is true
36+
if (request.SelfContained && !request.Rid.HasValue)
37+
{
38+
var error = $"RID is required when publishing self-contained applications. Please specify a RID for project {request.ProjectPath}";
39+
logger.Error(error);
40+
return Result.Failure<PublishResult>(error);
41+
}
42+
3543
var outputDirResult = PrepareOutputDirectory();
3644
if (outputDirResult.IsFailure)
3745
{
@@ -98,7 +106,7 @@ private Result<string> PrepareOutputDirectory()
98106
{
99107
var outputDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"dp-publish-{Guid.NewGuid():N}");
100108
System.IO.Directory.CreateDirectory(outputDir);
101-
logger.Information("Using temporary publish directory {Directory}", outputDir);
109+
logger.Debug("Using temporary publish directory {Directory}", outputDir);
102110
return outputDir;
103111
}, ex =>
104112
{
@@ -109,10 +117,9 @@ private Result<string> PrepareOutputDirectory()
109117

110118
private void LogPublishConfiguration(ProjectPublishRequest request)
111119
{
112-
var rid = request.Rid.Match(
120+
var ridDisplay = request.Rid.Match(
113121
value => value,
114-
() => request.SelfContained ? InferHostRid() : null);
115-
var ridDisplay = rid ?? "(default)";
122+
() => "(default)");
116123
logger.Information(
117124
"Executing dotnet publish for {ProjectPath} | Configuration: {Configuration} | Self-contained: {SelfContained} | Single-file: {SingleFile} | Trimmed: {Trimmed} | RID: {Rid}",
118125
request.ProjectPath,
@@ -129,12 +136,9 @@ private static string BuildArgs(ProjectPublishRequest r, string outputDir)
129136
sb.Append($"publish \"{r.ProjectPath}\" ");
130137
sb.Append($"-c {r.Configuration} ");
131138

132-
string? ridToUse = r.Rid.HasValue
133-
? r.Rid.Value
134-
: (r.SelfContained ? InferHostRid() : null);
135-
if (!string.IsNullOrWhiteSpace(ridToUse))
139+
if (r.Rid.HasValue)
136140
{
137-
sb.Append($"-r {ridToUse} ");
141+
sb.Append($"-r {r.Rid.Value} ");
138142
}
139143

140144
sb.Append(r.SelfContained ? "--self-contained true " : "--self-contained false ");
@@ -152,46 +156,4 @@ private static string BuildArgs(ProjectPublishRequest r, string outputDir)
152156
return sb.ToString();
153157
}
154158

155-
private static string? InferHostRid()
156-
{
157-
try
158-
{
159-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
160-
{
161-
return RuntimeInformation.OSArchitecture switch
162-
{
163-
System.Runtime.InteropServices.Architecture.X64 => "linux-x64",
164-
System.Runtime.InteropServices.Architecture.Arm64 => "linux-arm64",
165-
System.Runtime.InteropServices.Architecture.X86 => "linux-x86",
166-
System.Runtime.InteropServices.Architecture.Arm => "linux-arm",
167-
_ => null
168-
};
169-
}
170-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
171-
{
172-
return RuntimeInformation.OSArchitecture switch
173-
{
174-
System.Runtime.InteropServices.Architecture.X64 => "win-x64",
175-
System.Runtime.InteropServices.Architecture.Arm64 => "win-arm64",
176-
System.Runtime.InteropServices.Architecture.X86 => "win-x86",
177-
System.Runtime.InteropServices.Architecture.Arm => "win-arm",
178-
_ => null
179-
};
180-
}
181-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
182-
{
183-
return RuntimeInformation.OSArchitecture switch
184-
{
185-
System.Runtime.InteropServices.Architecture.X64 => "osx-x64",
186-
System.Runtime.InteropServices.Architecture.Arm64 => "osx-arm64",
187-
_ => null
188-
};
189-
}
190-
return null;
191-
}
192-
catch
193-
{
194-
return null;
195-
}
196-
}
197159
}

0 commit comments

Comments
 (0)