Skip to content

Commit 1c2c925

Browse files
committed
Merge pull request #450 from AndyGerlicher/PromoteMSB3644ToError
Promote Framework not found (MSB3644) warning to error
2 parents 599d48b + 0b465d6 commit 1c2c925

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

src/XMakeTasks/GetReferenceAssemblyPaths.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ namespace Microsoft.Build.Tasks
2121
public class GetReferenceAssemblyPaths : TaskExtension
2222
{
2323
#region Data
24+
/// <summary>
25+
/// Environment variable name for the override error on missing reference assembly directory.
26+
/// </summary>
27+
private const string WARNONNOREFERENCEASSEMBLYDIRECTORY = "MSBUILDWARNONNOREFERENCEASSEMBLYDIRECTORY";
28+
2429
/// <summary>
2530
/// This is the sentinel assembly for .NET FX 3.5 SP1
2631
/// Used to determine if SP1 of 3.5 is installed
@@ -43,7 +48,7 @@ public class GetReferenceAssemblyPaths : TaskExtension
4348
private IList<string> _tfmPathsNoProfile;
4449

4550
/// <summary>
46-
/// Target framework moniker string passd into the task
51+
/// Target framework moniker string passed into the task
4752
/// </summary>
4853
private string _targetFrameworkMoniker;
4954

@@ -241,7 +246,7 @@ public override bool Execute()
241246
_tfmPathsNoProfile = GetPaths(_rootPath, monikerWithNoProfile);
242247
}
243248

244-
// The path with out the profile is just the referecne assembly paths.
249+
// The path with out the profile is just the reference assembly paths.
245250
if (!targetingProfile)
246251
{
247252
_tfmPathsNoProfile = _tfmPaths;
@@ -281,10 +286,22 @@ private IList<String> GetPaths(string rootPath, FrameworkNameVersioning framewor
281286
pathsToReturn = ToolLocationHelper.GetPathToReferenceAssemblies(rootPath, frameworkmoniker);
282287
}
283288

284-
// No reference assembly paths could be found, log a warning as there could be future errors which may be confusing because of this.
289+
// No reference assembly paths could be found, log an error so an invalid build will not be produced.
290+
// 1/26/16: Note this was changed from a warning to an error (see GitHub #173). Also added the escape hatch
291+
// (set MSBUILDWARNONNOREFERENCEASSEMBLYDIRECTORY = 1) in case this causes issues.
292+
// TODO: This should be removed for Dev15
285293
if (pathsToReturn.Count == 0)
286294
{
287-
Log.LogWarningWithCodeFromResources("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkmoniker.ToString());
295+
var warn = Environment.GetEnvironmentVariable(WARNONNOREFERENCEASSEMBLYDIRECTORY);
296+
297+
if (string.Equals(warn, "1", StringComparison.Ordinal))
298+
{
299+
Log.LogWarningWithCodeFromResources("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkmoniker.ToString());
300+
}
301+
else
302+
{
303+
Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkmoniker.ToString());
304+
}
288305
}
289306

290307
return pathsToReturn;

src/XMakeTasks/UnitTests/GetReferencePaths_Tests.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,51 @@ public void TestGeneralFrameworkMonikerNonExistent()
157157
MockEngine engine = new MockEngine();
158158
GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
159159
getReferencePaths.BuildEngine = engine;
160-
// Make a framework which does not exist, intentional mispelling of framework
160+
// Make a framework which does not exist, intentional misspelling of framework
161161
getReferencePaths.TargetFrameworkMoniker = ".NetFramewok, Version=v99.0";
162-
getReferencePaths.Execute();
162+
bool success = getReferencePaths.Execute();
163+
Assert.False(success);
164+
string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
165+
Assert.Equal(0, returnedPaths.Length);
166+
string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName;
167+
Assert.Null(displayName);
168+
FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker);
169+
string message = ResourceUtilities.FormatResourceString("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkMoniker.ToString());
170+
engine.AssertLogContains("ERROR MSB3644: " + message);
171+
}
172+
173+
/// <summary>
174+
/// Test the case where the target framework moniker is empty when using MSBUILDWARNONNOREFERENCEASSEMBLYDIRECTORY
175+
/// override. Expect there to be a warning logged.
176+
/// TODO: This should be removed for Dev15 (override feature removed)
177+
/// </summary>
178+
[Fact]
179+
public void TestGeneralFrameworkMonikerNonExistentOverrideError()
180+
{
181+
MockEngine engine = new MockEngine();
182+
GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
183+
getReferencePaths.BuildEngine = engine;
184+
// Make a framework which does not exist, intentional misspelling of framework
185+
getReferencePaths.TargetFrameworkMoniker = ".NetFramewok, Version=v99.0";
186+
187+
try
188+
{
189+
Environment.SetEnvironmentVariable("MSBUILDWARNONNOREFERENCEASSEMBLYDIRECTORY", "1");
190+
bool success = getReferencePaths.Execute();
191+
Assert.True(success);
192+
}
193+
finally
194+
{
195+
Environment.SetEnvironmentVariable("MSBUILDWARNONNOREFERENCEASSEMBLYDIRECTORY", null);
196+
}
197+
163198
string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
164199
Assert.Equal(0, returnedPaths.Length);
165200
string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName;
166201
Assert.Null(displayName);
167202
FrameworkNameVersioning frameworkMoniker = new FrameworkNameVersioning(getReferencePaths.TargetFrameworkMoniker);
168203
string message = ResourceUtilities.FormatResourceString("GetReferenceAssemblyPaths.NoReferenceAssemblyDirectoryFound", frameworkMoniker.ToString());
169-
engine.AssertLogContains(message);
204+
engine.AssertLogContains("WARNING MSB3644: " + message);
170205
}
171206

172207
/// <summary>

0 commit comments

Comments
 (0)