提交 94d9c892 编写于 作者: A AlekseyTs

Enable command line compiler to produce XML doc comment file and embed it as a...

Enable command line compiler to produce XML doc comment file and embed it as a manifest resource at the same time. Fixes #444. (changeset 1396823)
上级 bb3f6e00
......@@ -1473,7 +1473,24 @@ private static void ValidateWin32Settings(string win32ResourceFile, string win32
return null;
}
Func<Stream> dataProvider = () => new FileStream(fullPath, FileMode.Open, FileAccess.Read);
Func<Stream> dataProvider = () =>
{
// Use FileShare.ReadWrite because the file could be opened by the current process.
// For example, it is an XML doc file produced by the build.
var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
// Lock the entire content to prevent others from modifying it while we are reading.
try
{
stream.Lock(0, long.MaxValue);
return stream;
}
catch
{
stream.Dispose();
throw;
}
};
return new ResourceDescription(resourceName, fileName, dataProvider, isPublic, embedded, checkArgs: false);
}
......
......@@ -7230,6 +7230,54 @@ public void M(ushort i)
.WithLocation(4, 26)
.WithWarningAsError(false));
}
[Fact, WorkItem(1091972, "DevDiv"), WorkItem(444, "CodePlex")]
public void Bug1091972()
{
var dir = Temp.CreateDirectory();
var src = dir.CreateFile("a.cs");
src.WriteAllText(
@"
/// <summary>ABC...XYZ</summary>
class C {
static void Main()
{
var textStreamReader = new System.IO.StreamReader(typeof(C).Assembly.GetManifestResourceStream(""doc.xml""));
System.Console.WriteLine(textStreamReader.ReadToEnd());
}
} ");
var output = RunAndGetOutput(CSharpCompilerExecutable, String.Format("/nologo /doc:doc.xml /out:out.exe /resource:doc.xml {0}", src.ToString()), startFolder: dir.ToString());
Assert.Equal("", output.Trim());
Assert.True(File.Exists(Path.Combine(dir.ToString(), "doc.xml")));
var expected =
@"<?xml version=""1.0""?>
<doc>
<assembly>
<name>out</name>
</assembly>
<members>
<member name=""T:C"">
<summary>ABC...XYZ</summary>
</member>
</members>
</doc>".Trim();
using (var reader = new StreamReader(Path.Combine(dir.ToString(), "doc.xml")))
{
var content = reader.ReadToEnd();
Assert.Equal(expected, content.Trim());
}
output = RunAndGetOutput(Path.Combine(dir.ToString(), "out.exe"), startFolder: dir.ToString());
Assert.Equal(expected, output.Trim());
CleanupAllGeneratedFiles(src.Path);
}
}
[DiagnosticAnalyzer]
......
......@@ -1385,7 +1385,20 @@ lVbRuntimePlus:
Return Nothing
End If
Dim dataProvider As Func(Of Stream) = Function() New FileStream(fullPath, FileMode.Open, FileAccess.Read)
Dim dataProvider As Func(Of Stream) = Function()
' Use FileShare.ReadWrite because the file could be opened by the current process.
' For example, it Is an XML doc file produced by the build.
Dim stream = New FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
' Lock the entire content to prevent others from modifying it while we are reading.
Try
stream.Lock(0, Long.MaxValue)
Return stream
Catch
stream.Dispose()
Throw
End Try
End Function
Return New ResourceDescription(resourceName, fileName, dataProvider, isPublic, embedded, checkArgs:=False)
End Function
......
......@@ -6756,6 +6756,56 @@ End Module"
CleanupAllGeneratedFiles(file.Path)
End Sub
<Fact, WorkItem(1091972, "DevDiv"), WorkItem(444, "CodePlex")>
Public Sub Bug1091972()
Dim dir = Temp.CreateDirectory()
Dim src = dir.CreateFile("a.vb")
src.WriteAllText(
<text>
''' &lt;summary&gt;ABC...XYZ&lt;/summary&gt;
Class C
Shared Sub Main()
Dim textStreamReader = New System.IO.StreamReader(GetType(C).Assembly.GetManifestResourceStream("doc.xml"))
System.Console.WriteLine(textStreamReader.ReadToEnd())
End Sub
End Class
</text>.Value.Replace(vbLf, vbCrLf))
Dim output = RunAndGetOutput(BasicCompilerExecutable, String.Format("/nologo /doc:doc.xml /out:out.exe /resource:doc.xml {0}", src.ToString()), startFolder:=dir.ToString())
AssertOutput(<text></text>, output)
Assert.True(File.Exists(Path.Combine(dir.ToString(), "doc.xml")))
Dim expected = <text>
<![CDATA[
<?xml version="1.0"?>
<doc>
<assembly>
<name>
out
</name>
</assembly>
<members>
<member name="T:C">
<summary>ABC...XYZ</summary>
</member>
</members>
</doc>
]]>
</text>
Using reader As New StreamReader(Path.Combine(dir.ToString(), "doc.xml"))
Dim content = reader.ReadToEnd()
AssertOutput(expected, content)
End Using
output = RunAndGetOutput(Path.Combine(dir.ToString(), "out.exe"), startFolder:=dir.ToString())
AssertOutput(expected, output)
CleanupAllGeneratedFiles(src.Path)
End Sub
End Class
<DiagnosticAnalyzer(LanguageNames.VisualBasic)>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册