CsharpToColouredHTML.Core
1.0.4
See the version list below for details.
dotnet add package CsharpToColouredHTML.Core --version 1.0.4
NuGet\Install-Package CsharpToColouredHTML.Core -Version 1.0.4
<PackageReference Include="CsharpToColouredHTML.Core" Version="1.0.4" />
paket add CsharpToColouredHTML.Core --version 1.0.4
#r "nuget: CsharpToColouredHTML.Core, 1.0.4"
// Install CsharpToColouredHTML.Core as a Cake Addin #addin nuget:?package=CsharpToColouredHTML.Core&version=1.0.4 // Install CsharpToColouredHTML.Core as a Cake Tool #tool nuget:?package=CsharpToColouredHTML.Core&version=1.0.4
CsharpToColouredHTML
This library tries to convert C# code into pure HTML with some lines of CSS that
make it look as if that was inside Visual Studio or Visual Studio Code.
Why?
Motivation for doing it was that I wanted to put C# code fragments on website,
but I didn't like the colours that were provided by popular sytnax highlighting solutions - they were not so IDE-ish,
but also I wanted to have server-side rendering, so users aren't required to have JavaScript enabled* in order to see colors.
* Ironically demo page uses a few lines of js just to make messing with the demo more sane
Security Considerations
Even despite performing escaping
I still recommend to use it only on trusted inputs, at least for now.
Demo
You can try live demo that's avaliable at: https://csharp-colors.xyz/
Or use it in not so serious projects: https://www.nuget.org/packages/CsharpToColouredHTML.Core/
.NET CLI: dotnet add package CsharpToColouredHTML.Core --version 1.0.4
Sample Usage:
var html = new CsharpColourer().ProcessSourceCode(code, new HTMLEmitter());
Console.WriteLine(html);
var myCustomCSS = "<style>...</style>";
var html = new CsharpColourer().ProcessSourceCode(code, new HTMLEmitter(myCustomCSS));
Console.WriteLine(html);
Example input (code.txt
):
using System.Text;
using Microsoft.CodeAnalysis.Classification;
namespace CsharpToColouredHTML.Core;
public class ConsoleEmitter : IEmitter
{
public ConsoleEmitter(bool addDiagnosticInfo = false)
{
this.addDiagnosticInfo = addDiagnosticInfo;
}
private readonly StringBuilder _sb = new StringBuilder();
private readonly bool addDiagnosticInfo;
public string Text { get; private set; }
public void Emit(List<Node> nodes)
{
Console.ResetColor();
Text = "";
_sb.Clear();
foreach (var node in nodes)
{
EmitNode(node);
}
Text = _sb.ToString();
}
public void EmitNode(Node node)
{
if (node.ClassificationType == ClassificationTypeNames.ClassName)
{
Console.ForegroundColor = ConsoleColor.Red;
}
else if (node.ClassificationType == ClassificationTypeNames.NamespaceName)
{
Console.ForegroundColor = ConsoleColor.Green;
}
else if (node.ClassificationType == ClassificationTypeNames.Identifier)
{
Console.ForegroundColor = ConsoleColor.Green;
}
else if (node.ClassificationType == ClassificationTypeNames.Keyword)
{
Console.ForegroundColor = ConsoleColor.Yellow;
}
else if (node.ClassificationType == ClassificationTypeNames.StringLiteral)
{
Console.ForegroundColor = ConsoleColor.Cyan;
}
else if (node.ClassificationType == ClassificationTypeNames.LocalName)
{
Console.ForegroundColor = ConsoleColor.Blue;
}
else if (node.ClassificationType == ClassificationTypeNames.MethodName)
{
Console.ForegroundColor = ConsoleColor.Red;
}
else if (node.ClassificationType == ClassificationTypeNames.Punctuation)
{
Console.ForegroundColor = ConsoleColor.White;
}
else if (node.ClassificationType == ClassificationTypeNames.Operator)
{
Console.ForegroundColor = ConsoleColor.White;
}
else if (node.ClassificationType == ClassificationTypeNames.ControlKeyword)
{
Console.ForegroundColor = ConsoleColor.DarkRed;
}
else if (node.ClassificationType == ClassificationTypeNames.VerbatimStringLiteral)
{
Console.ForegroundColor = ConsoleColor.DarkRed;
}
else if (node.ClassificationType == ClassificationTypeNames.StringLiteral)
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
}
else if (node.ClassificationType == ClassificationTypeNames.ParameterName)
{
Console.ForegroundColor = ConsoleColor.Yellow;
}
else
{
Console.ResetColor();
}
_sb.Append(node.TextWithTrivia);
Console.Write($"{node.TextWithTrivia}");
if (addDiagnosticInfo)
{
_sb.Append($"({node.ClassificationType})");
Console.Write($"({node.ClassificationType})");
}
Console.ResetColor();
}
}
<a name="ex1">How generated HTML looks in browser:</a>
Generated HTML Code:
this is html page
<br>
<style>
.background{font-family:monaco,Consolas,LucidaConsole,monospace;background-color:#1E1E1E;}.numeric{color:#b5cea8;}.method{color:#DCDCAA;}.class{color:#4EC9B0;}.keyword{color:#569cd6;}.blue{color:#9CDCFE;}.white{color:#D4D4D4;}.string{color:#ce9178;}.interface{color:#b8d7a3;}.control{color:#C586C0;}.internal_error{color:#FF0D0D;}
</style>
<pre class="background">
<span class="keyword">using</span><span class="white"> System</span><span class="white">.</span><span class="white">Text</span><span class="white">;</span><span class="keyword">
using</span><span class="white"> Microsoft</span><span class="white">.</span><span class="white">CodeAnalysis</span><span class="white">.</span><span class="white">Classification</span><span class="white">;</span><span class="keyword">
namespace</span><span class="white"> CsharpToColouredHTML</span><span class="white">.</span><span class="white">Core</span><span class="white">;</span><span class="keyword">
public</span><span class="keyword"> class</span><span class="class"> ConsoleEmitter</span><span class="white"> :</span><span class="interface"> IEmitter</span><span class="white">
{</span><span class="keyword">
public</span><span class="class"> ConsoleEmitter</span><span class="white">(</span><span class="keyword">bool</span><span class="blue"> addDiagnosticInfo</span><span class="white"> =</span><span class="keyword"> false</span><span class="white">)</span><span class="white">
{</span><span class="keyword">
this</span><span class="white">.</span><span class="white">addDiagnosticInfo</span><span class="white"> =</span><span class="blue"> addDiagnosticInfo</span><span class="white">;</span><span class="white">
}</span><span class="keyword">
private</span><span class="keyword"> readonly</span><span class="class"> StringBuilder</span><span class="white"> _sb</span><span class="white"> =</span><span class="keyword"> new</span><span class="class"> StringBuilder</span><span class="white">(</span><span class="white">)</span><span class="white">;</span><span class="keyword">
private</span><span class="keyword"> readonly</span><span class="keyword"> bool</span><span class="white"> addDiagnosticInfo</span><span class="white">;</span><span class="keyword">
public</span><span class="keyword"> string</span><span class="white"> Text</span><span class="white"> {</span><span class="keyword"> get</span><span class="white">;</span><span class="keyword"> private</span><span class="keyword"> set</span><span class="white">;</span><span class="white"> }</span><span class="keyword">
public</span><span class="keyword"> void</span><span class="method"> Emit</span><span class="white">(</span><span class="class">List</span><span class="white"><</span><span class="class">Node</span><span class="white">></span><span class="blue"> nodes</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="method">ResetColor</span><span class="white">(</span><span class="white">)</span><span class="white">;</span><span class="white">
Text</span><span class="white"> =</span><span class="string"> ""</span><span class="white">;</span><span class="white">
_sb</span><span class="white">.</span><span class="method">Clear</span><span class="white">(</span><span class="white">)</span><span class="white">;</span><span class="control">
foreach</span><span class="white"> (</span><span class="keyword">var</span><span class="blue"> node</span><span class="control"> in</span><span class="blue"> nodes</span><span class="white">)</span><span class="white">
{</span><span class="method">
EmitNode</span><span class="white">(</span><span class="blue">node</span><span class="white">)</span><span class="white">;</span><span class="white">
}</span><span class="white">
Text</span><span class="white"> =</span><span class="white"> _sb</span><span class="white">.</span><span class="method">ToString</span><span class="white">(</span><span class="white">)</span><span class="white">;</span><span class="white">
}</span><span class="keyword">
public</span><span class="keyword"> void</span><span class="method"> EmitNode</span><span class="white">(</span><span class="class">Node</span><span class="blue"> node</span><span class="white">)</span><span class="white">
{</span><span class="control">
if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">ClassName</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">Red</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">NamespaceName</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">Green</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">Identifier</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">Green</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">Keyword</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">Yellow</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">StringLiteral</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">Cyan</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">LocalName</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">Blue</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">MethodName</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">Red</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">Punctuation</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">White</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">Operator</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">White</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">ControlKeyword</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">DarkRed</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">VerbatimStringLiteral</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">DarkRed</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">StringLiteral</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">DarkGreen</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="control"> if</span><span class="white"> (</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white"> ==</span><span class="class"> ClassificationTypeNames</span><span class="white">.</span><span class="white">ParameterName</span><span class="white">)</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="white">ForegroundColor</span><span class="white"> =</span><span class="class"> ConsoleColor</span><span class="white">.</span><span class="white">Yellow</span><span class="white">;</span><span class="white">
}</span><span class="control">
else</span><span class="white">
{</span><span class="class">
Console</span><span class="white">.</span><span class="method">ResetColor</span><span class="white">(</span><span class="white">)</span><span class="white">;</span><span class="white">
}</span><span class="white">
_sb</span><span class="white">.</span><span class="method">Append</span><span class="white">(</span><span class="blue">node</span><span class="white">.</span><span class="white">TextWithTrivia</span><span class="white">)</span><span class="white">;</span><span class="class">
Console</span><span class="white">.</span><span class="method">Write</span><span class="white">(</span><span class="string">$"</span><span class="white">{</span><span class="blue">node</span><span class="white">.</span><span class="white">TextWithTrivia</span><span class="white">}</span><span class="string">"</span><span class="white">)</span><span class="white">;</span><span class="control">
if</span><span class="white"> (</span><span class="white">addDiagnosticInfo</span><span class="white">)</span><span class="white">
{</span><span class="white">
_sb</span><span class="white">.</span><span class="method">Append</span><span class="white">(</span><span class="string">$"</span><span class="string">(</span><span class="white">{</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white">}</span><span class="string">)</span><span class="string">"</span><span class="white">)</span><span class="white">;</span><span class="class">
Console</span><span class="white">.</span><span class="method">Write</span><span class="white">(</span><span class="string">$"</span><span class="string">(</span><span class="white">{</span><span class="blue">node</span><span class="white">.</span><span class="white">ClassificationType</span><span class="white">}</span><span class="string">)</span><span class="string">"</span><span class="white">)</span><span class="white">;</span><span class="white">
}</span><span class="class">
Console</span><span class="white">.</span><span class="method">ResetColor</span><span class="white">(</span><span class="white">)</span><span class="white">;</span><span class="white">
}</span><span class="white">
}</span></pre>
Second Example:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable disable
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using EnvDTE;
using Microsoft;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Task = System.Threading.Tasks.Task;
namespace Roslyn.Compilers.Extension
{
[Guid("31C0675E-87A4-4061-A0DD-A4E510FCCF97")]
public sealed class CompilerPackage : AsyncPackage
{
public static string RoslynHive = null;
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true);
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var reg = (ILocalRegistry2)await GetServiceAsync(typeof(SLocalRegistry)).ConfigureAwait(true);
cancellationToken.ThrowIfCancellationRequested();
Assumes.Present(reg);
var packagePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string localRegistryRoot;
reg.GetLocalRegistryRoot(out localRegistryRoot);
var registryParts = localRegistryRoot.Split('\\');
// Is it a valid Hive looks similar to:
// 'Software\Microsoft\VisualStudio\14.0' 'Software\Microsoft\VisualStudio\14.0Roslyn' 'Software\Microsoft\VSWinExpress\14.0'
if (registryParts.Length >= 4)
{
var skuName = registryParts[2];
var hiveName = registryParts[3];
RoslynHive = string.Format(@"{0}.{1}", registryParts[2], registryParts[3]);
await WriteMSBuildFilesAsync(packagePath, RoslynHive, cancellationToken).ConfigureAwait(true);
try
{
Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.DisableMarkDirty = true;
Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.SetGlobalProperty("RoslynHive", RoslynHive);
}
finally
{
Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.DisableMarkDirty = false;
}
}
}
private async Task WriteMSBuildFilesAsync(string packagePath, string hiveName, CancellationToken cancellationToken)
{
// A map of the file name to the content we need to ensure exists in the file
var filesToWrite = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
// The props we want to be included as early as possible since we want our tasks to be used and
// to ensure our setting of targets path happens early enough
filesToWrite.Add(await GetMSBuildRelativePathAsync($@"Imports\Microsoft.Common.props\ImportBefore\Roslyn.Compilers.Extension.{hiveName}.props", cancellationToken).ConfigureAwait(true),
$@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup Condition=""'$(RoslynHive)' == '{hiveName}'"">
<CSharpCoreTargetsPath>{packagePath}\Microsoft.CSharp.Core.targets</CSharpCoreTargetsPath>
<VisualBasicCoreTargetsPath>{packagePath}\Microsoft.VisualBasic.Core.targets</VisualBasicCoreTargetsPath>
</PropertyGroup>
<UsingTask TaskName=""Microsoft.CodeAnalysis.BuildTasks.Csc"" AssemblyFile=""{packagePath}\Microsoft.Build.Tasks.CodeAnalysis.dll"" Condition=""'$(RoslynHive)' == '{hiveName}'"" />
<UsingTask TaskName=""Microsoft.CodeAnalysis.BuildTasks.Vbc"" AssemblyFile=""{packagePath}\Microsoft.Build.Tasks.CodeAnalysis.dll"" Condition=""'$(RoslynHive)' == '{hiveName}'"" />
</Project>");
// This targets content we want to be included later since the project file might touch UseSharedCompilation
var targetsContent =
$@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup Condition=""'$(RoslynHive)' == '{hiveName}' and '$(UseSharedCompilation)' == 'false'"">
<CscToolPath>{packagePath}</CscToolPath>
<CscToolExe>csc.exe</CscToolExe>
<VbcToolPath>{packagePath}</VbcToolPath>
<VbcToolExe>vbc.exe</VbcToolExe>
</PropertyGroup>
</Project>";
filesToWrite.Add(await GetMSBuildRelativePathAsync($@"Microsoft.CSharp.targets\ImportBefore\Roslyn.Compilers.Extension.{hiveName}.targets", cancellationToken).ConfigureAwait(true), targetsContent);
filesToWrite.Add(await GetMSBuildRelativePathAsync($@"Microsoft.VisualBasic.targets\ImportBefore\Roslyn.Compilers.Extension.{hiveName}.targets", cancellationToken).ConfigureAwait(true), targetsContent);
// First we want to ensure any Roslyn files with our hive name that we aren't writing -- this is probably
// leftovers from older extensions
var msbuildDirectory = new DirectoryInfo(await GetMSBuildPathAsync(cancellationToken).ConfigureAwait(true));
if (msbuildDirectory.Exists)
{
foreach (var file in msbuildDirectory.EnumerateFiles($"*Roslyn*{hiveName}*", SearchOption.AllDirectories))
{
if (!filesToWrite.ContainsKey(file.FullName))
{
file.Delete();
}
}
}
try
{
foreach (var fileAndContents in filesToWrite)
{
var parentDirectory = new DirectoryInfo(Path.GetDirectoryName(fileAndContents.Key));
parentDirectory.Create();
// If we already know the file has the same contents, then we can skip
if (File.Exists(fileAndContents.Key) && File.ReadAllText(fileAndContents.Key) == fileAndContents.Value)
{
continue;
}
File.WriteAllText(fileAndContents.Key, fileAndContents.Value);
}
}
catch (Exception e)
{
var msg =
$@"{e.Message}
To reload the Roslyn compiler package, close Visual Studio and any MSBuild processes, then restart Visual Studio.";
VsShellUtilities.ShowMessageBox(
this,
msg,
null,
OLEMSGICON.OLEMSGICON_WARNING,
OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
}
}
private async Task<string> GetMSBuildVersionStringAsync(CancellationToken cancellationToken)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var dte = (DTE)await GetServiceAsync(typeof(SDTE)).ConfigureAwait(true);
var parts = dte.Version.Split('.');
if (parts.Length != 2)
{
throw new Exception($"Unrecognized Visual Studio Version: {dte.Version}");
}
int majorVersion = int.Parse(parts[0]);
if (majorVersion >= 16)
{
// Starting in Visual Studio 2019, the folder is just called "Current". See
// https://github.com/Microsoft/msbuild/issues/4149 for further commentary.
return "Current";
}
else
{
return majorVersion + ".0";
}
}
private async Task<string> GetMSBuildPathAsync(CancellationToken cancellationToken)
{
var version = await GetMSBuildVersionStringAsync(cancellationToken).ConfigureAwait(true);
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
return Path.Combine(localAppData, $@"Microsoft\MSBuild\{version}");
}
private async Task<string> GetMSBuildRelativePathAsync(string relativePath, CancellationToken cancellationToken)
{
return Path.Combine(await GetMSBuildPathAsync(cancellationToken).ConfigureAwait(true), relativePath);
}
}
}
<a name="ex2">Generated HTML inside Browser:</a>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.0.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CsharpToColouredHTML.Core:
Package | Downloads |
---|---|
Markdown.ColorCode.CSharpToColoredHtml
An extension for Markdig that adds syntax highlighting to code through the power of ColorCode, boosted with the CsharpToColouredHTML.Core package. |
|
StatiCSharp.Parser.CSharpToColoredHtml
This is a port of Swiftly1's CsharpToColouredHTML for StatiC#, a static website generator for C# developers. C# code parts of your markdown files are rendered to look as if it was inside Visual Studio or Visual Studio Code. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
2.0.0 | 86 | 12/20/2024 | |
1.0.44 | 1,411 | 3/24/2024 | |
1.0.43 | 145 | 3/24/2024 | |
1.0.42 | 402 | 2/17/2024 | |
1.0.41 | 436 | 9/2/2023 | |
1.0.40 | 258 | 5/1/2023 | |
1.0.39 | 286 | 3/18/2023 | |
1.0.38 | 338 | 1/31/2023 | |
1.0.37 | 384 | 12/27/2022 | |
1.0.36 | 348 | 12/8/2022 | |
1.0.35 | 392 | 11/28/2022 | |
1.0.34 | 389 | 11/21/2022 | |
1.0.33 | 377 | 11/18/2022 | |
1.0.32 | 402 | 11/11/2022 | |
1.0.31 | 394 | 11/10/2022 | |
1.0.30 | 413 | 11/9/2022 | |
1.0.29 | 429 | 10/30/2022 | |
1.0.28 | 432 | 10/3/2022 | |
1.0.27 | 447 | 9/17/2022 | |
1.0.26 | 465 | 9/11/2022 | |
1.0.25 | 474 | 9/10/2022 | |
1.0.24 | 493 | 8/20/2022 | |
1.0.23 | 464 | 8/14/2022 | |
1.0.22 | 500 | 7/15/2022 | |
1.0.21 | 522 | 7/14/2022 | |
1.0.20 | 505 | 7/13/2022 | |
1.0.19 | 536 | 7/13/2022 | |
1.0.18 | 479 | 7/7/2022 | |
1.0.17 | 495 | 7/7/2022 | |
1.0.16 | 511 | 6/26/2022 | |
1.0.15 | 523 | 6/26/2022 | |
1.0.14 | 503 | 6/21/2022 | |
1.0.13 | 510 | 6/16/2022 | |
1.0.12 | 481 | 6/16/2022 | |
1.0.11 | 557 | 1/30/2022 | |
1.0.10 | 507 | 1/22/2022 | |
1.0.9 | 512 | 1/20/2022 | |
1.0.8 | 519 | 1/20/2022 | |
1.0.7 | 518 | 1/17/2022 | |
1.0.6 | 571 | 1/17/2022 | |
1.0.5 | 556 | 1/17/2022 | |
1.0.4 | 352 | 12/31/2021 | |
1.0.3 | 342 | 12/31/2021 | |
1.0.2 | 347 | 12/31/2021 | |
1.0.1 | 348 | 12/28/2021 | |
1.0.0 | 391 | 12/15/2021 |