-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
34 lines (32 loc) · 1.58 KB
/
Directory.Build.targets
File metadata and controls
34 lines (32 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<Project>
<UsingTask TaskName="StripImgTags"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<InputFile ParameterType="System.String" Required="true" />
<OutputFile ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs"><![CDATA[
var content = File.ReadAllText(InputFile);
content = Regex.Replace(content, @"(?<=\S)[ \t]*<img[^>]*/?>[ \t]*(?=\S)", " ", RegexOptions.IgnoreCase);
content = Regex.Replace(content, @"[ \t]*<img[^>]*/?>[ \t]*\r?\n?", string.Empty, RegexOptions.IgnoreCase | RegexOptions.Multiline);
Directory.CreateDirectory(Path.GetDirectoryName(OutputFile));
File.WriteAllText(OutputFile, content);
]]></Code>
</Task>
</UsingTask>
<PropertyGroup>
<PackageReadmeSource Condition="'$(PackageReadmeSource)' == ''">$(MSBuildProjectDirectory)/README.md</PackageReadmeSource>
</PropertyGroup>
<Target Name="StripHtmlImages" BeforeTargets="_GetPackageFiles" Condition="'$(IsPackable)' == 'true'">
<StripImgTags InputFile="$(PackageReadmeSource)"
OutputFile="$(IntermediateOutputPath)README.md" />
<ItemGroup>
<None Include="$(IntermediateOutputPath)README.md" Pack="true" PackagePath="\" />
<None Include="$(MSBuildThisFileDirectory)docs/images/logo-128.png" Pack="true" PackagePath="\" />
</ItemGroup>
</Target>
</Project>