Skip to content

Commit 1993456

Browse files
author
Julien Couvreur
committed
Addressing feedback from Chuck. Handle scenario where input isn't ref assembly. Hook assembly redirect.
1 parent d881d9e commit 1993456

File tree

7 files changed

+37
-13
lines changed

7 files changed

+37
-13
lines changed

src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ internal sealed override CommandLineArguments CommonParse(IEnumerable<string> ar
11781178
AddDiagnostic(diagnostics, diagnosticOptions, ErrorCode.ERR_NoRefOutWhenRefOnly);
11791179
}
11801180

1181-
if (metadataReferences.Any(r => r.Properties.EmbedInteropTypes) && (refOnly || outputRefFilePath != null))
1181+
if ((refOnly || outputRefFilePath != null) && metadataReferences.Any(r => r.Properties.EmbedInteropTypes))
11821182
{
11831183
AddDiagnostic(diagnostics, diagnosticOptions, ErrorCode.ERR_NoEmbeddedTypeWhenRefOutOrRefOnly);
11841184
}

src/Compilers/Core/MSBuildTask/CopyRefAssembly.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public sealed class CopyRefAssembly : Task
2020
[Required]
2121
public string DestinationPath { get; set; }
2222

23+
static CopyRefAssembly()
24+
{
25+
AssemblyResolution.Install();
26+
}
27+
2328
public CopyRefAssembly()
2429
{
2530
TaskResources = ErrorString.ResourceManager;
@@ -45,20 +50,27 @@ public override bool Execute()
4550
Log.LogMessageFromResources(MessageImportance.High, "CopyRefAssembly_BadSource3", SourcePath, e.Message, e.StackTrace);
4651
}
4752

48-
try
53+
if (source.Equals(Guid.Empty))
54+
{
55+
Log.LogMessageFromResources(MessageImportance.High, "CopyRefAssembly_SourceNotRef1", SourcePath);
56+
}
57+
else
4958
{
50-
Guid destination = ExtractMvid(DestinationPath);
59+
try
60+
{
61+
Guid destination = ExtractMvid(DestinationPath);
5162

52-
if (source.Equals(destination))
63+
if (!source.Equals(Guid.Empty) && source.Equals(destination))
64+
{
65+
Log.LogMessageFromResources(MessageImportance.Low, "CopyRefAssembly_SkippingCopy1", DestinationPath);
66+
return true;
67+
}
68+
}
69+
catch (Exception)
5370
{
54-
Log.LogMessageFromResources(MessageImportance.Low, "CopyRefAssembly_SkippingCopy1", DestinationPath);
55-
return true;
71+
Log.LogMessageFromResources(MessageImportance.High, "CopyRefAssembly_BadDestination1", DestinationPath);
5672
}
5773
}
58-
catch (Exception)
59-
{
60-
Log.LogMessageFromResources(MessageImportance.High, "CopyRefAssembly_BadDestination1", DestinationPath);
61-
}
6274
}
6375

6476
return Copy();

src/Compilers/Core/MSBuildTask/ErrorString.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/Core/MSBuildTask/ErrorString.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@
154154
<data name="CopyRefAssembly_SkippingCopy1" xml:space="preserve">
155155
<value>Reference assembly "{0}" already has latest information. Leaving it untouched.</value>
156156
</data>
157+
<data name="CopyRefAssembly_SourceNotRef1" xml:space="preserve">
158+
<value>Could not extract the MVID from "{0}". Are you sure it is a reference assembly?</value>
159+
</data>
157160
<data name="CopyRefAssembly_BadSource3" xml:space="preserve">
158161
<value>Failed to check the content hash of the source ref assembly '{0}': {1}
159162
{2}</value>

src/Compilers/VisualBasic/Portable/CommandLine/VisualBasicCommandLineParser.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ lVbRuntimePlus:
12031203
AddDiagnostic(diagnostics, ERRID.ERR_NoRefOutWhenRefOnly)
12041204
End If
12051205

1206-
If metadataReferences.Any(Function(r) r.Properties.EmbedInteropTypes) AndAlso (refOnly OrElse outputRefFileName IsNot Nothing) Then
1206+
If (refOnly OrElse outputRefFileName IsNot Nothing) AndAlso metadataReferences.Any(Function(r) r.Properties.EmbedInteropTypes) Then
12071207
AddDiagnostic(diagnostics, ERRID.ERR_NoEmbeddedTypeWhenRefOutOrRefOnly)
12081208
End If
12091209

src/Compilers/VisualBasic/Portable/VBResources.Designer.vb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/VisualBasic/Portable/VBResources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5472,7 +5472,7 @@
54725472
<value>Do not use refout when using refonly.</value>
54735473
</data>
54745474
<data name="ERR_NoEmbeddedTypeWhenRefOutOrRefOnly" xml:space="preserve">
5475-
<value>Cannot compile embed types when using /refout or /refonly.</value>
5475+
<value>Cannot embed types when using /refout or /refonly.</value>
54765476
</data>
54775477
<data name="ERR_NoNetModuleOutputWhenRefOutOrRefOnly" xml:space="preserve">
54785478
<value>Cannot compile net modules when using /refout or /refonly.</value>

0 commit comments

Comments
 (0)