提交 712808f7 编写于 作者: N nmgafter

529546-Extend EmitMetadataOnly to support resources

and add parameters to the API for upcoming anticipated changes to support reference assemblies. (changeset 1310516)
上级 7260514a
......@@ -123,6 +123,7 @@
<Compile Include="Compilation\DebugInformationKind.cs" />
<Compile Include="Compilation\EmitResult.cs" />
<Compile Include="Compilation\Extensions.cs" />
<Compile Include="Compilation\MetadataOnlyEmitOptions.cs" />
<Compile Include="Compilation\ParseOptions.cs" />
<Compile Include="Compilation\Platform.cs" />
<Compile Include="Compilation\PreprocessingSymbolInfo.cs" />
......
......@@ -1353,17 +1353,24 @@ internal void EnsureAnonymousTypeTemplates(CancellationToken cancellationToken)
/// are errors.
/// </summary>
/// <param name="peStream">Stream to which the PE image with metadata will be written.</param>
/// <param name="xmlDocStream">Stream to which the compilation's XML documentation will be written. Null to forego XML generation.</param>
/// <param name="xmlDocumentationStream">Stream to which the compilation's XML documentation will be written. Null to forego XML generation.</param>
/// <param name="outputName">Name of the compilation: file name and extension. Null to use the existing output name.
/// CAUTION: If this is set to a (non-null) value other than the existing compilation output name, then internals-visible-to
/// and assembly references may not work as expected. In particular, things that were visible at bind time, based on the
/// name of the compilation, may not be visible at runtime and vice-versa.
/// </param>
/// <param name="win32Resources">Stream from which the compilation's Win32 resources will be read (in RES format).
/// Null to indicate that there are none. The RES format begins with a null resource entry.</param>
/// <param name="manifestResources">List of the compilation's managed resources. Null to indicate that there are none.</param>
/// <param name="emitOptions">Options controlling the emitted metadata.</param>
/// <param name="cancellationToken">To cancel the emit process.</param>
public EmitResult EmitMetadataOnly(
Stream peStream,
string outputName = null,
Stream xmlDocStream = null,
Stream xmlDocumentationStream = null,
Stream win32Resources = null,
IEnumerable<ResourceDescription> manifestResources = null,
MetadataOnlyEmitOptions emitOptions = default(MetadataOnlyEmitOptions),
CancellationToken cancellationToken = default(CancellationToken))
{
if (peStream == null)
......@@ -1376,9 +1383,9 @@ internal void EnsureAnonymousTypeTemplates(CancellationToken cancellationToken)
outputName,
pdbFilePath: null,
pdbStream: null,
xmlDocumentationStream: xmlDocStream,
win32Resources: null,
manifestResources: null,
xmlDocumentationStream: xmlDocumentationStream,
win32Resources: win32Resources,
manifestResources: manifestResources,
metadataOnly: true,
testData: null,
cancellationToken: cancellationToken);
......@@ -1578,17 +1585,29 @@ private EmitResult ToEmitResultAndFree(DiagnosticBag diagnostics, bool success)
metadataDiagnostics = DiagnosticBag.GetInstance();
try
{
// when in deterministic mode, we need to seek and read the stream to compute a deterministic MVID.
// If the underlying stream isn't readable and seekable, we need to use a temp stream.
string deterministicString = this.Feature("deterministic");
bool deterministic = deterministicString != null && deterministicString != "false";
var writeToTempStream = deterministic && !(outputStream.CanRead && outputStream.CanSeek);
var streamToWrite = writeToTempStream ? new MemoryStream() : outputStream;
Cci.PeWriter.WritePeToStream(
new EmitContext(moduleBeingBuilt, null, metadataDiagnostics),
this.MessageProvider,
outputStream,
streamToWrite,
pdbWriter,
metadataOnly,
foldIdenticalMethodBodies,
deterministic,
cancellationToken);
if (writeToTempStream)
{
streamToWrite.Position = 0;
streamToWrite.CopyTo(outputStream);
streamToWrite.Dispose();
}
}
catch (Cci.PdbWritingException ex)
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis
{
/// <summary>
/// Options that can be used to control metadata-only emit.
/// </summary>
[Flags]
public enum MetadataOnlyEmitOptions : int
{
/// <summary>
/// Tolerate errors, producing a PE stream and a success result even in the presence of (some) errors. This parameter is currently ignored.
/// </summary>
TolerateErrors = 1 << 0,
/// <summary>
/// If not set, exclude (some) private members from the generated assembly when they do not
/// affect the language semantics of the resulting assembly. This option is currently ignored.
/// </summary>
IncludePrivateMembers = 1 << 1,
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册