Skip to content
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

fix XML Documentation (Rewrite AddXmlLanguage and add to Nupkg Audit) #1495

Merged
merged 7 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .props/_Nupkg.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup>
Expand Down
17 changes: 17 additions & 0 deletions .scripts/release_NupkgAudit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ function Get-DoesXmlDocExist ([string]$dllPath) {
Test-Condition (Test-Path $docFile) $message $requirement;
}

function Get-DoesXmlDocContainsLang ([string]$dllPath) {
# CONFIRM .XML DOCUMENTATION FILE EXISTS WITH EACH DLL
[string]$docFile = $dllPath -replace ".dll", ".xml";

[bool]$result = $false;
[string]$searchString = '<doc xml:lang="en">';

if (Test-Path $docFile) {
$result = select-string -path $docFile -Pattern $searchString -Quiet;
}

$message = "XML Documentation:";
$requirement = "Must contain xml:lang='en' ";
Test-Condition ($result) $message $requirement;
}

function Get-DoesDllVersionsMatch ([string]$dllPath) {
# CONFIRM Assembly version matches File version
[string]$fileVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($dllPath).FileVersion;
Expand Down Expand Up @@ -323,6 +339,7 @@ function Start-EvaluateNupkg ($nupkgPath) {
Get-DoesDllVersionsMatch $_.FullName;

Get-DoesXmlDocExist $_.FullName;
Get-DoesXmlDocContainsLang $_.FullName;
}
}

Expand Down
71 changes: 14 additions & 57 deletions .targets/AddXmlLanguage.targets
Original file line number Diff line number Diff line change
@@ -1,80 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="Info_AddXmlLanguageTargets" BeforeTargets="Build" Condition=" $(Internal_Logging) == 'true' ">
<Message Text="Info: AddXmlLanguage.targets imported by $(MSBuildProjectName)." Importance="high"/>
</Target>


<UsingTask TaskName="InjectXmlLanguage" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<InputFiles ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<FilePath ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<!--<Reference Include="System" />-->
<Using Namespace="System" />
<Using Namespace="System.Diagnostics" />
<Using Namespace="System.IO" />
<!--
Not sure where the requirement of xml:lang="en" came from. But to address it - hacking is the only way now:
https://social.msdn.microsoft.com/forums/en-us/70b984eb-f490-4494-8fbc-12fe4a62e5e4/xmllang-on-doc-for-xml-doc-comments?forum=xmlandnetfx
-->
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage("Called InjectXmlLanguage");
foreach (var inputFilePath in InputFiles.Select(f => f.ItemSpec))
{
Log.LogMessage("Fixing {0}", inputFilePath);
string filePath = inputFilePath;
if (filePath.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
{
filePath = filePath.Substring(0, filePath.Length - 3) + "xml";
}

if (filePath.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
{
string[] files = null;
int starIndex = filePath.IndexOf('*');
if (starIndex >= 0)
{
string dir = filePath.Substring(0, starIndex);
if (string.IsNullOrEmpty(dir))
{
dir = ".";
}
<Code Type="Fragment" Language="cs"><![CDATA[
Log.LogMessage(MessageImportance.High, "InjectXmlLanguage -> {0}", FilePath);

string file = Path.GetFileName(filePath.Substring(starIndex));
files = Directory.GetFiles(dir, file, SearchOption.AllDirectories);
}
else
{
files = new[] { filePath };
}

foreach (string fileName in files)
{
if (File.Exists(fileName))
{
Log.LogMessage("Processing XML: {0}", fileName);
string text = File.ReadAllText(fileName);
text = text.Replace("<doc>", "<doc xml:lang=\"en\">");
File.WriteAllText(fileName, text);
}
}
}
if (File.Exists(FilePath))
{
string text = File.ReadAllText(FilePath);
text = text.Replace("<doc>", "<doc xml:lang=\"en\">");
File.WriteAllText(FilePath, text);
}
else
{
Log.LogError("InjectXmlLanguage: Assembly XML Doc file not found in bin folder.");
}
]]>
</Code>
]]></Code>
</Task>
</UsingTask>

<Target Name="FixXmlDocumentation" AfterTargets="AfterBuild" DependsOnTargets="AfterBuild" Condition="$(OS) == 'Windows_NT'">
<InjectXmlLanguage InputFiles="$(DocumentationFile)" />
<InjectXmlLanguage FilePath="$(OutputPath)\$(AssemblyName).XML" />
</Target>

<Target Name="AddXmlDocToNugetPackage" Condition="$(OS) == 'Windows_NT'">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)$(TargetName).xml" />
</ItemGroup>
</Target>
</Project>
74 changes: 0 additions & 74 deletions BASE/AddXmlLanguage.targets

This file was deleted.

3 changes: 0 additions & 3 deletions BASE/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,4 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DefineConstants>$(DefineConstants);TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);AddXmlDocToNugetPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion BASE/Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="Signing.targets" />
<Import Project="AddXmlLanguage.targets" />
<Import Project="$(TargetsRoot)\AddXmlLanguage.targets" />

</Project>
1 change: 0 additions & 1 deletion BASE/src/Microsoft.ApplicationInsights/Product.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
<PropertyGroup>
<RootNamespace>Microsoft.ApplicationInsights</RootNamespace>
<AssemblyName>$(RootNamespace)</AssemblyName>
<DocumentationFile>$(OutputPath)\$(TargetFramework)\$(AssemblyName).XML</DocumentationFile>
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion BASE/src/ServerTelemetryChannel/Product.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
<PropertyGroup>
<RootNamespace>Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel</RootNamespace>
<AssemblyName>Microsoft.AI.ServerTelemetryChannel</AssemblyName>
<DocumentationFile>$(OutputPath)\$(TargetFramework)\$(AssemblyName).XML</DocumentationFile>
</PropertyGroup>
</Project>
70 changes: 0 additions & 70 deletions LOGGING/AddXmlLanguage.targets

This file was deleted.

3 changes: 0 additions & 3 deletions LOGGING/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,4 @@
<DefineConstants>$(DefineConstants);TRACE</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);AddXmlDocToNugetPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion LOGGING/Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="Signing.targets" />
<Import Project="AddXmlLanguage.targets" />
<Import Project="$(TargetsRoot)\AddXmlLanguage.targets" />

</Project>
5 changes: 0 additions & 5 deletions LOGGING/src/Product.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,4 @@
<OutputPath>$([System.IO.Path]::GetFullPath( $(OutputPath) ))\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<DocumentationFile>$(OutputPath)\$(TargetFramework)\$(AssemblyName).XML</DocumentationFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
<PackageTags>$(PackageTags)aspnetcore;</PackageTags>
</PropertyGroup>

<PropertyGroup>
<!--Package Settings-->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<!--Symbols Settings-->
<DebugType>full</DebugType>
Expand Down Expand Up @@ -112,4 +107,5 @@
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
</ItemGroup>

<Import Project="$(TargetsRoot)\AddXmlLanguage.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
<PackageTags>$(PackageTags)worker;console;backgroundtasks;</PackageTags>
</PropertyGroup>

<PropertyGroup>
<!--Package Settings-->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<!--Symbols Settings-->
<DebugType>full</DebugType>
Expand Down Expand Up @@ -88,4 +83,6 @@

<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
</ItemGroup>

<Import Project="$(TargetsRoot)\AddXmlLanguage.targets" />
</Project>
Loading