Skip to content

Commit 42975d6

Browse files
committed
move knownstrings to library layer ot help keep in sync
1 parent 3826f4b commit 42975d6

File tree

5 files changed

+41
-40
lines changed

5 files changed

+41
-40
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace Microsoft.NET.Build.Containers;
2+
3+
public static class KnownStrings
4+
{
5+
public static class Properties
6+
{
7+
public static string ContainerBaseImage = nameof(ContainerBaseImage);
8+
public static string ContainerRegistry = nameof(ContainerRegistry);
9+
public static string ContainerImageName = nameof(ContainerImageName);
10+
public static string ContainerImageTag = nameof(ContainerImageTag);
11+
public static string ContainerImageTags = nameof(ContainerImageTags);
12+
public static string ContainerWorkingDirectory = nameof(ContainerWorkingDirectory);
13+
public static string ContainerEntrypoint = nameof(ContainerEntrypoint);
14+
public static string UseAppHost = nameof(UseAppHost);
15+
public static string ContainerLabel = nameof(ContainerLabel);
16+
public static string SelfContained = nameof(SelfContained);
17+
public static string ContainerPort = nameof(ContainerPort);
18+
public static string ContainerEnvironmentVariable = nameof(ContainerEnvironmentVariable);
19+
20+
public static string ComputeContainerConfig = nameof(ComputeContainerConfig);
21+
public static string AssemblyName = nameof(AssemblyName);
22+
public static string ContainerBaseRegistry = nameof(ContainerBaseRegistry);
23+
public static string ContainerBaseName = nameof(ContainerBaseName);
24+
public static string ContainerBaseTag = nameof(ContainerBaseTag);
25+
}
26+
27+
public static class ErrorCodes
28+
{
29+
public static string CONTAINER001 = nameof(CONTAINER001);
30+
public static string CONTAINER004 = nameof(CONTAINER004);
31+
public static string CONTAINER005 = nameof(CONTAINER005);
32+
}
33+
}

Microsoft.NET.Build.Containers/ParseContainerProperties.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public override bool Execute()
115115
else
116116
{
117117
validTags = Array.Empty<string>();
118-
Log.LogError(null, "CONTAINER004", "Container.InvalidTag", null, 0, 0, 0, 0, $"Invalid {nameof(ContainerImageTag)} provided: {{0}}. Image tags must be alphanumeric, underscore, hyphen, or period.", ContainerImageTag);
118+
Log.LogError(null, KnownStrings.ErrorCodes.CONTAINER004, "Container.InvalidTag", null, 0, 0, 0, 0, $"Invalid {nameof(ContainerImageTag)} provided: {{0}}. Image tags must be alphanumeric, underscore, hyphen, or period.", ContainerImageTag);
119119
}
120120
}
121121
else if (ContainerImageTags.Length != 0 && TryValidateTags(ContainerImageTags, out var valids, out var invalids))
@@ -128,7 +128,7 @@ public override bool Execute()
128128
{ Length: 1 } => ($"Invalid {nameof(ContainerImageTags)} provided: {{0}}. {nameof(ContainerImageTags)} must be a semicolon-delimited list of valid image tags. Image tags must be alphanumeric, underscore, hyphen, or period.", invalids[0]),
129129
_ => ($"Invalid {nameof(ContainerImageTags)} provided: {{0}}. {nameof(ContainerImageTags)} must be a semicolon-delimited list of valid image tags. Image tags must be alphanumeric, underscore, hyphen, or period.", String.Join(", ", invalids))
130130
};
131-
Log.LogError(null, "CONTAINER004", "Container.InvalidTag", null, 0, 0, 0, 0, message, args);
131+
Log.LogError(null, KnownStrings.ErrorCodes.CONTAINER004, "Container.InvalidTag", null, 0, 0, 0, 0, message, args);
132132
return !Log.HasLoggedErrors;
133133
}
134134
}
@@ -163,10 +163,10 @@ public override bool Execute()
163163

164164
try
165165
{
166-
if (!ContainerHelpers.NormalizeImageName(ContainerImageName, out string? normalizedImageName))
166+
if (!ContainerHelpers.NormalizeImageName(ContainerImageName, out var normalizedImageName))
167167
{
168-
Log.LogMessage(MessageImportance.High, $"'{ContainerImageName}' was not a valid container image name, it was normalized to {normalizedImageName}");
169-
NewContainerImageName = normalizedImageName ?? "";
168+
Log.LogMessage(null, KnownStrings.ErrorCodes.CONTAINER001, "Container.InvalidImageName", null, 0, 0, 0, 0, MessageImportance.High, "'{0}' was not a valid container image name, it was normalized to '{1}'", nameof(ContainerImageName), normalizedImageName);
169+
NewContainerImageName = normalizedImageName;
170170
}
171171
else
172172
{

Test.Microsoft.NET.Build.Containers.Filesystem/KnownStrings.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

Test.Microsoft.NET.Build.Containers.Filesystem/ParseContainerPropertiesTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
2-
using Microsoft.NET.Build.Containers.Tasks;
3-
using static Test.Microsoft.NET.Build.Containers.KnownStrings;
1+
using static Microsoft.NET.Build.Containers.KnownStrings;
2+
using static Microsoft.NET.Build.Containers.KnownStrings.Properties;
43

54
namespace Test.Microsoft.NET.Build.Containers.Tasks
65
{

Test.Microsoft.NET.Build.Containers.Filesystem/TargetsTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using Microsoft.Build.Evaluation;
2-
using Microsoft.Build.Framework;
3-
using Microsoft.Build.Locator;
4-
using static Test.Microsoft.NET.Build.Containers.KnownStrings;
1+
using static Microsoft.NET.Build.Containers.KnownStrings.Properties;
52

63
namespace Test.Microsoft.NET.Build.Containers.Targets;
74

0 commit comments

Comments
 (0)