Skip to content

Commit

Permalink
Migrate Microsoft.DocAsCode.Common, Microsoft.DocAsCode.Plugins, and …
Browse files Browse the repository at this point in the history
…Microsoft.DocAsCode.YamlSerialization projects to .NET Standard 2.0.

dotnet#1963.
  • Loading branch information
tintoy committed Sep 29, 2017
1 parent 95589ca commit 771d3e9
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 23 deletions.
7 changes: 3 additions & 4 deletions src/Microsoft.DocAsCode.Common/AmbientContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Microsoft.DocAsCode.Common
{
using System;
using System.Runtime.Remoting.Messaging;
using System.Threading;

[Serializable]
Expand Down Expand Up @@ -106,17 +105,17 @@ public void Dispose()

private static object[] GetCurrentContextRaw()
{
return CallContext.LogicalGetData(AMBCTX_NAME) as object[];
return LogicalCallContext.GetData(AMBCTX_NAME) as object[];
}

private static void SetCurrentContextRaw(object[] raw)
{
CallContext.LogicalSetData(AMBCTX_NAME, raw);
LogicalCallContext.SetData(AMBCTX_NAME, raw);
}

private static void RemoveAmbientContext()
{
CallContext.FreeNamedDataSlot(AMBCTX_NAME);
LogicalCallContext.FreeData(AMBCTX_NAME);
}

private object[] ToObjectArray()
Expand Down
7 changes: 3 additions & 4 deletions src/Microsoft.DocAsCode.Common/ComputerResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Microsoft.DocAsCode.Common
{
using System;
using System.Runtime.Remoting.Messaging;
using System.Threading;

[Serializable]
Expand Down Expand Up @@ -46,17 +45,17 @@ private static void SetResourceType(ComputerResource resource)
{
if (resource == null)
{
CallContext.FreeNamedDataSlot(nameof(ComputerResource));
LogicalCallContext.FreeData(nameof(ComputerResource));
}
else
{
CallContext.LogicalSetData(nameof(ComputerResource), resource);
LogicalCallContext.SetData(nameof(ComputerResource), resource);
}
}

private static ComputerResource GetResourceType()
{
return (ComputerResource)CallContext.LogicalGetData(nameof(ComputerResource));
return (ComputerResource)LogicalCallContext.GetData(nameof(ComputerResource));
}

public static int GetAvailableCpuResource() => _resources.CpuResource.CurrentCount;
Expand Down
5 changes: 2 additions & 3 deletions src/Microsoft.DocAsCode.Common/Loggers/LoggerFileScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Microsoft.DocAsCode.Common
{
using System;
using System.Runtime.Remoting.Messaging;

public sealed class LoggerFileScope : IDisposable
{
Expand All @@ -28,12 +27,12 @@ public void Dispose()

internal static string GetFileName()
{
return CallContext.LogicalGetData(nameof(LoggerFileScope)) as string;
return LogicalCallContext.GetData(nameof(LoggerFileScope)) as string;
}

private static void SetFileName(string fileName)
{
CallContext.LogicalSetData(nameof(LoggerFileScope), fileName);
LogicalCallContext.SetData(nameof(LoggerFileScope), fileName);
}

public static object Capture()
Expand Down
5 changes: 2 additions & 3 deletions src/Microsoft.DocAsCode.Common/Loggers/LoggerPhaseScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Microsoft.DocAsCode.Common
{
using System;
using System.Runtime.Remoting.Messaging;

public sealed class LoggerPhaseScope : IDisposable
{
Expand Down Expand Up @@ -75,12 +74,12 @@ public void Dispose()

internal static string GetPhaseName()
{
return CallContext.LogicalGetData(nameof(LoggerPhaseScope)) as string;
return LogicalCallContext.GetData(nameof(LoggerPhaseScope)) as string;
}

private void SetPhaseName(string phaseName)
{
CallContext.LogicalSetData(nameof(LoggerPhaseScope), phaseName);
LogicalCallContext.SetData(nameof(LoggerPhaseScope), phaseName);
}

public static object Capture()
Expand Down
18 changes: 18 additions & 0 deletions src/Microsoft.DocAsCode.Common/LogicalCallContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Concurrent;
using System.Threading;

namespace Microsoft.DocAsCode.Common
{
/// <summary>
/// A NETStandard-friendly replacement for CallContext.
/// </summary>
public static class LogicalCallContext
{
static readonly ConcurrentDictionary<string, AsyncLocal<object>> _data = new ConcurrentDictionary<string, AsyncLocal<object>>();

public static void SetData(string key, object data) => _data.GetOrAdd(key, _ => new AsyncLocal<object>()).Value = data;

public static object GetData(string key) => _data.TryGetValue(key, out AsyncLocal<object> data) ? data.Value : null;
public static void FreeData(string key) => _data.TryRemove(key, out _);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../Shared/base.props" />

<Import Project="../Shared/base.netstandard.props" />
<ItemGroup>
<ProjectReference Include="..\Microsoft.DocAsCode.Plugins\Microsoft.DocAsCode.Plugins.csproj" />
<ProjectReference Include="..\Microsoft.DocAsCode.YamlSerialization\Microsoft.DocAsCode.YamlSerialization.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net461' OR '$(TargetFramework)' == 'net46' OR '$(TargetFramework)' == 'net452'">
<Reference Include="System.Xml" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../Shared/base.props" />
<Import Project="../Shared/base.netstandard.props" />

<ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../Shared/base.props" />
<Import Project="../Shared/base.netstandard.props" />

<ItemGroup>
<PackageReference Include="YamlDotNet.Signed" Version="4.1.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="YamlDotNet.Signed" Version="4.2.2" />
</ItemGroup>
</Project>
58 changes: 58 additions & 0 deletions src/Shared/base.netstandard.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<Project>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>

<!-- Note: by convention assembly should be named after the root namespace -->
<AssemblyName Condition=" '$(AssemblyName)' == '' ">$(MSBuildProjectName)</AssemblyName>
<AssemblyTitle Condition=" '$(AssemblyTitle)' == '' ">$(MSBuildProjectName)</AssemblyTitle>
<Product Condition=" '$(Product)' == '' ">$(MSBuildProjectName)</Product>
<PackageId Condition=" '$(PackageId)' == '' ">$(MSBuildProjectName)</PackageId>
<Company Condition=" '$(Company)' == '' ">Microsoft</Company>
<Copyright Condition=" '$(Copyright)' == '' ">Copyright © Microsoft docfx 2015-2017</Copyright>

<PackageProjectUrl Condition=" '$(PackageProjectUrl)' == '' ">https://github.com/dotnet/docfx</PackageProjectUrl>
<PackageLicenseUrl Condition=" '$(PackageLicenseUrl)' == '' ">https://github.com/dotnet/docfx/blob/dev/LICENSE</PackageLicenseUrl>

<VersionCSFile Condition="'$(VersionCSFile)' == ''">$(MSBuildThisFileDirectory)..\..\TEMP\version.cs</VersionCSFile>
<VersionFileExists Condition="Exists($(VersionCSFile))" >true</VersionFileExists>

<GenerateAssemblyVersionAttribute Condition=" '$(VersionFileExists)' == 'true' ">false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute Condition=" '$(VersionFileExists)' == 'true' ">false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute Condition=" '$(VersionFileExists)' == 'true' ">false</GenerateAssemblyInformationalVersionAttribute>

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<RootNamespace Condition=" '$(RootNamespace)' == '' ">$(AssemblyName)</RootNamespace>
<DebugSymbols>true</DebugSymbols>
<ErrorReport>prompt</ErrorReport>

<!-- Note: unless explicitly specified, we will generate DLL -->
<OutputType Condition=" '$(OutputType)' == '' ">Library</OutputType>
<Prefer32Bit>false</Prefer32Bit>
<RestorePackages Condition=" '$(RestorePackages)' == '' ">true</RestorePackages>

<!-- Note: get rid of vshost.exe since we don't gain much benefits -->
<UseVSHostingProcess>false</UseVSHostingProcess>
<WarningLevel>4</WarningLevel>

</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Condition="Exists($(VersionCSFile))" Include="$(VersionCSFile)" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<!-- Common references -->
</ItemGroup>
</Project>

0 comments on commit 771d3e9

Please sign in to comment.