-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore write-resource-to-text tests #4830
Changes from 7 commits
9aa42bb
86c74a5
3a6da3e
a89802a
bc04a15
1de44ef
60f260c
2c99582
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2603,6 +2603,12 @@ private bool ProcessFile(string inFile, string outFileOrDir) | |
{ | ||
ReadResources(inFile, _useSourcePath, outFileOrDir); | ||
} | ||
catch (InputFormatNotSupportedException) | ||
{ | ||
_logger.LogErrorWithCodeFromResources(null, FileUtilities.GetFullPathNoThrow(inFile), 0, 0, 0, 0, | ||
"GenerateResource.CoreSupportsLimitedScenarios"); | ||
return false; | ||
} | ||
catch (MSBuildResXException msbuildResXException) | ||
{ | ||
_logger.LogErrorWithCodeFromResources(null, FileUtilities.GetFullPathNoThrow(inFile), 0, 0, 0, 0, | ||
|
@@ -2988,7 +2994,7 @@ private void ReadResources(String filename, bool shouldUseSourcePath, String out | |
#if FEATURE_ASSEMBLY_LOADFROM | ||
ReadAssemblyResources(filename, outFileOrDir); | ||
#else | ||
_logger.LogError("Reading resources from Assembly not supported on .NET Core MSBuild"); | ||
throw new InputFormatNotSupportedException("Reading resources from Assembly not supported on .NET Core MSBuild"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it advantageous to throw instead of just logging an error? Are you trying to reduce duplicate output? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logging an error here is nonfatal, so the experience with going through this codepath was:
Since there were already exception-based error paths in |
||
#endif | ||
} | ||
else | ||
|
@@ -3046,10 +3052,10 @@ private void ReadResources(String filename, bool shouldUseSourcePath, String out | |
case Format.Binary: | ||
#if FEATURE_RESX_RESOURCE_READER | ||
ReadResources(reader, new ResourceReader(filename), filename); // closes reader for us | ||
break; | ||
#else | ||
_logger.LogError("ResGen.exe not supported on .NET Core MSBuild"); | ||
throw new InputFormatNotSupportedException("Reading resources from binary .resources not supported on .NET Core MSBuild"); | ||
#endif | ||
break; | ||
|
||
default: | ||
// We should never get here, we've already checked the format | ||
|
@@ -3387,8 +3393,13 @@ private bool HaveSystemResourcesExtensionsReference | |
|
||
PopulateAssemblyNames(); | ||
|
||
foreach (var assemblyName in _assemblyNames) | ||
foreach (AssemblyNameExtension assemblyName in _assemblyNames) | ||
{ | ||
if (assemblyName == null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would they be null? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what happens if an assembly name can't be extracted from a reference for some reason in |
||
{ | ||
continue; | ||
} | ||
|
||
if (string.Equals(assemblyName.Name, "System.Resources.Extensions", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
_haveSystemResourcesExtensionsReference = true; | ||
|
@@ -3761,14 +3772,16 @@ private void WriteTextResources(ReaderInfo reader, String fileName) | |
{ | ||
using (StreamWriter writer = FileUtilities.OpenWrite(fileName, false, Encoding.UTF8)) | ||
{ | ||
foreach (LiveObjectResource entry in reader.resources) | ||
foreach (IResource resource in reader.resources) | ||
{ | ||
String key = entry.Name; | ||
Object v = entry.Value; | ||
LiveObjectResource entry = resource as LiveObjectResource; | ||
|
||
String key = entry?.Name; | ||
Object v = entry?.Value; | ||
String value = v as String; | ||
if (value == null) | ||
{ | ||
_logger.LogErrorWithCodeFromResources(null, fileName, 0, 0, 0, 0, "GenerateResource.OnlyStringsSupported", key, v.GetType().FullName); | ||
_logger.LogErrorWithCodeFromResources(null, fileName, 0, 0, 0, 0, "GenerateResource.OnlyStringsSupported", key, v?.GetType().FullName); | ||
} | ||
else | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Microsoft.Build.Tasks.ResourceHandling | ||
{ | ||
[Serializable] | ||
internal class InputFormatNotSupportedException : Exception | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason you can't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a custom exception type makes detecting this error condition easy using a catch-specific-type block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tracing how it's currently caught, I believe a FormatException will still have the exact same effect. Also, I don't see anywhere that you try to catch it; do you have plans for adding something like that in the future? If not, you're breaking something that could otherwise be caught by an ArgumentException, failing more cleanly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since it's a standard exception type, other code could insert a
This is harder to distinguish since other places could throw |
||
{ | ||
public InputFormatNotSupportedException() | ||
{ | ||
} | ||
|
||
public InputFormatNotSupportedException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public InputFormatNotSupportedException(string message, Exception innerException) : base(message, innerException) | ||
{ | ||
} | ||
|
||
protected InputFormatNotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context) | ||
{ | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) Is this line necessary? According to the File.WriteAllText documentation, even if the file did exist it would be overwritten
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's preexisting but no, I don't think it is. I'll remove.