Skip to content
Closed
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
7 changes: 0 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,12 @@ jobs:
fail-fast: false
matrix:
configuration: [ debug, release ]
projectloadstyle: [ net35, net40, All ]
os: [ windows-latest, ubuntu-latest ]
exclude:
- projectloadstyle: net35
os: ubuntu-latest
- projectloadstyle: net40
os: ubuntu-latest

env:
RunPeVerify: true
Solution_Name: Open-XML-SDK.slnx
Configuration: ${{ matrix.configuration }}
ProjectLoadStyle: ${{ matrix.projectloadstyle }}

runs-on: ${{ matrix.os }}

Expand Down
55 changes: 12 additions & 43 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,54 +32,23 @@
<Version>$(GitVersion_NuGetVersionV2)</Version>
</PropertyGroup>

<!-- Due to the need to test .NET 3.5 and .NET 4.0 builds, we have separate configurations that
allow us to build and test them. These are mostly done in CI, but may be useful at dev time. -->
<Choose>
<When Condition=" '$(ProjectLoadStyle)' == 'net35' ">
<PropertyGroup>
<!-- We have some internal types that conflict -->
<NoWarn>$(NoWarn);CS1685</NoWarn>
<ProductTargetFrameworks>net35</ProductTargetFrameworks>
<FrameworkTargetFrameworks>net35</FrameworkTargetFrameworks>
<TestTargetFrameworks>net472</TestTargetFrameworks>
<AssetsTargetFrameworks>net472</AssetsTargetFrameworks>
<LatestTargetFramework>net472</LatestTargetFramework>
<SamplesFrameworks>net472</SamplesFrameworks>
<DefineConstants>$(DefineConstants);FEATURE_NO_VALIDATOR_CANCELLATIONTOKEN</DefineConstants>
</PropertyGroup>
</When>
<When Condition=" '$(ProjectLoadStyle)' == 'net40' ">
<PropertyGroup>
<!-- We have some internal types that conflict -->
<NoWarn>$(NoWarn);CS1685</NoWarn>
<ProductTargetFrameworks>net40</ProductTargetFrameworks>
<FrameworkTargetFrameworks>net40</FrameworkTargetFrameworks>
<TestTargetFrameworks>net472</TestTargetFrameworks>
<AssetsTargetFrameworks>net472</AssetsTargetFrameworks>
<LatestTargetFramework>net472</LatestTargetFramework>
<SamplesFrameworks>net472</SamplesFrameworks>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<ProductTargetFrameworks>netstandard2.0;net10.0;net8.0;net35;net40;net46</ProductTargetFrameworks>
<FrameworkTargetFrameworks>netstandard2.0;net10.0;net6.0;net8.0;net35;net40;net46</FrameworkTargetFrameworks>
<AssetsTargetFrameworks>netstandard2.0;net472</AssetsTargetFrameworks>
<TestTargetFrameworks>net8.0;net10.0</TestTargetFrameworks>
<TestTargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TestTargetFrameworks);net472</TestTargetFrameworks>
<LatestTargetFramework>net10.0</LatestTargetFramework>
<SamplesFrameworks>net8.0;net10.0</SamplesFrameworks>
<SamplesFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(SamplesFrameworks);net472</SamplesFrameworks>
<DefineConstants Condition=" '$(TargetFramework)' != 'net35' And '$(TargetFramework)' != 'net40' And '$(TargetFramework)' != 'net46' And '$(TargetFramework)' != 'net472' ">$(DefineConstants);FEATURE_ASYNC_SAX_XML</DefineConstants>
</PropertyGroup>
</Otherwise>
</Choose>
<PropertyGroup>
<ProductTargetFrameworks>netstandard2.0;net10.0;net8.0;net46</ProductTargetFrameworks>
<FrameworkTargetFrameworks>netstandard2.0;net10.0;net6.0;net8.0;net46</FrameworkTargetFrameworks>
<AssetsTargetFrameworks>netstandard2.0;net472</AssetsTargetFrameworks>
<TestTargetFrameworks>net8.0;net10.0</TestTargetFrameworks>
<TestTargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TestTargetFrameworks);net472</TestTargetFrameworks>
<LatestTargetFramework>net10.0</LatestTargetFramework>
<SamplesFrameworks>net8.0;net10.0</SamplesFrameworks>
<SamplesFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(SamplesFrameworks);net472</SamplesFrameworks>
<DefineConstants Condition=" '$(TargetFramework)' != 'net46' And '$(TargetFramework)' != 'net472' ">$(DefineConstants);FEATURE_ASYNC_SAX_XML</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<SupportsNetStandard>false</SupportsNetStandard>
<SupportsNetStandard Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.0'))">true</SupportsNetStandard>
<IsFramework>false</IsFramework>
<IsFramework Condition=" '$(TargetFramework)' == 'net35' OR $(TargetFramework.StartsWith('net4')) ">true</IsFramework>
<IsFramework Condition=" $(TargetFramework.StartsWith('net4')) ">true</IsFramework>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
7 changes: 0 additions & 7 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
<Reference Condition="$(IsFramework)" Include="WindowsBase" />
</ItemGroup>

<!-- By default, the .NET 3.5 build will try to use the ResGen.exe included with .NET 3.5, but that doesn't work on .NET Core-->
<PropertyGroup Condition=" '$(TargetFramework)' == 'net35' ">
<GenerateResourceMSBuildArchitecture>CurrentArchitecture</GenerateResourceMSBuildArchitecture>
<GenerateResourceMSBuildRuntime>CurrentRuntime</GenerateResourceMSBuildRuntime>
<ResGenExecuteAsTool>false</ResGenExecuteAsTool>
</PropertyGroup>

<PropertyGroup>
<IncludeFrameworkShims Condition=" '$(IncludeFrameworkShims)' == '' ">false</IncludeFrameworkShims>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ private sealed class RandomNumberGeneratorFeature : IRandomNumberGeneratorFeatur

public void Dispose()
{
#if !NET35
_generator.Dispose();
#endif
}

public void GetBytes(byte[] bytes)
Expand Down
9 changes: 0 additions & 9 deletions src/DocumentFormat.OpenXml.Framework/Framework/Cached.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@ namespace DocumentFormat.OpenXml.Framework
{
internal static class Cached
{
#if !NET35 && !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Array<T>() => System.Array.Empty<T>();
#else
public static T[] Array<T>() => EmptyArray<T>.Value;

private static class EmptyArray<T>
{
internal static readonly T[] Value = new T[0];
}
#endif

public static ReadOnlyCollection<T> ReadOnlyCollection<T>() => ReadOnlyCollectionCache<T>.Value;

Expand Down
10 changes: 0 additions & 10 deletions src/DocumentFormat.OpenXml.Framework/Framework/DelegatingStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
using System.Diagnostics;
using System.IO;

#if !NET35 && !NET40
using System.Threading;
using System.Threading.Tasks;
#endif

namespace DocumentFormat.OpenXml.Framework;

Expand Down Expand Up @@ -111,12 +109,10 @@ public override int ReadByte()
return _innerStream.ReadByte();
}

#if !NET35 && !NET40
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return _innerStream.ReadAsync(buffer, offset, count, cancellationToken);
}
#endif

#if NET6_0_OR_GREATER
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
Expand All @@ -132,12 +128,10 @@ public override void CopyTo(Stream destination, int bufferSize)
}
#endif

#if !NET35 && !NET40
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
{
return _innerStream.CopyToAsync(destination, bufferSize, cancellationToken);
}
#endif

#endregion Read

Expand All @@ -148,12 +142,10 @@ public override void Flush()
_innerStream.Flush();
}

#if !NET35 && !NET40
public override Task FlushAsync(CancellationToken cancellationToken)
{
return _innerStream.FlushAsync(cancellationToken);
}
#endif

public override void SetLength(long value)
{
Expand All @@ -177,12 +169,10 @@ public override void WriteByte(byte value)
_innerStream.WriteByte(value);
}

#if !NET35 && !NET40
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return _innerStream.WriteAsync(buffer, offset, count, cancellationToken);
}
#endif

#if NET6_0_OR_GREATER
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
using System;
using System.IO;

#if !NET35 && !NET40
using System.Threading;
using System.Threading.Tasks;
#endif

namespace DocumentFormat.OpenXml.Framework;

Expand All @@ -24,9 +22,7 @@ public override void Flush()
{
}

#if !NET35 && !NET40
public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask;
#endif

public override void SetLength(long value) => throw new NotSupportedException();

Expand All @@ -41,10 +37,8 @@ public override void Write(ReadOnlySpan<byte> buffer)
public override void WriteByte(byte value)
=> throw new NotSupportedException();

#if !NET35 && !NET40
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
=> throw new NotSupportedException();
#endif

#if NET6_0_OR_GREATER
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
using System;
using System.Collections.Generic;

#if NET35
using System.Linq;
#endif

namespace DocumentFormat.OpenXml.Framework.Schema
{
internal class ParticlePath : IComparable<ParticlePath>, IEquatable<ParticlePath>
Expand Down Expand Up @@ -42,11 +38,7 @@ public int CompareTo(ParticlePath? other)
=> CompareTo(other, true);

public override string ToString()
#if NET35
=> string.Join(", ", _values.Select(v => v.ToString()).ToArray());
#else
=> string.Join(", ", (IEnumerable<ParticlePathItem>)_values);
#endif

private int CompareTo(ParticlePath? other, bool isCompare)
{
Expand Down
4 changes: 0 additions & 4 deletions src/DocumentFormat.OpenXml.Framework/OpenXmlElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1802,11 +1802,7 @@ private protected XmlReader CreateXmlReader(string outerXml)

if (OpenXmlElementContext is not null)
{
#if NET35
OpenXmlElementContext.XmlReaderSettings.ProhibitDtd = true; // set true explicitly for security fix
#else
OpenXmlElementContext.XmlReaderSettings.DtdProcessing = DtdProcessing.Prohibit; // set to prohibit explicitly for security fix
#endif
return XmlConvertingReaderFactory.Create(stringReader, Features.GetNamespaceResolver(), OpenXmlElementContext.XmlReaderSettings);
}
else
Expand Down
4 changes: 0 additions & 4 deletions src/DocumentFormat.OpenXml.Framework/OpenXmlElementContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ internal static XmlReaderSettings CreateDefaultXmlReaderSettings()
{
return new XmlReaderSettings
{
#if NET35
ProhibitDtd = true,
#else
DtdProcessing = DtdProcessing.Prohibit,
#endif
NameTable = new NameTable(),

// Set IgnoreWhitespace to false for the SDK to handle the whitespace node type. We have to do this because
Expand Down
8 changes: 0 additions & 8 deletions src/DocumentFormat.OpenXml.Framework/OpenXmlMiscNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ public OpenXmlMiscNode(XmlNodeType nodeType, string outerXml)
{
XmlReaderSettings settings = new XmlReaderSettings
{
#if NET35
ProhibitDtd = true, // set true explicitly for security fix
#else
DtdProcessing = DtdProcessing.Prohibit, // set to prohibit explicitly for security fix
#endif
};

using (XmlReader xmlReader = XmlConvertingReaderFactory.Create(stringReader, Features.GetNamespaceResolver(), settings))
Expand Down Expand Up @@ -121,11 +117,7 @@ public override string LocalName
{
XmlReaderSettings settings = new XmlReaderSettings
{
#if NET35
ProhibitDtd = true,
#else
DtdProcessing = DtdProcessing.Prohibit,
#endif
};

using (XmlReader xmlReader = XmlConvertingReaderFactory.Create(stringReader, Features.GetNamespaceResolver(), settings))
Expand Down
4 changes: 0 additions & 4 deletions src/DocumentFormat.OpenXml.Framework/OpenXmlPartReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,7 @@ private XmlReader CreateReader(Stream partStream, bool closeInput, long maxChara
MaxCharactersInDocument = maxCharactersInPart,
CloseInput = closeInput,
IgnoreWhitespace = ignoreWhitespace,
#if NET35
ProhibitDtd = true,
#else
DtdProcessing = DtdProcessing.Prohibit,
#endif
};

var xmlReader = XmlConvertingReaderFactory.Create(partStream, _resolver, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ internal bool LoadFromPart(OpenXmlPart openXmlPart, Stream partStream, bool stri
// set MaxCharactersInDocument to limit the part size on loading DOM.
context.XmlReaderSettings.MaxCharactersInDocument = openXmlPart.MaxCharactersInPart;

#if NET35
context.XmlReaderSettings.ProhibitDtd = true; // set true explicitly for security fix
#else
context.XmlReaderSettings.DtdProcessing = DtdProcessing.Prohibit; // set to prohibit explicitly for security fix
#endif

using (var xmlReader = XmlConvertingReaderFactory.Create(partStream, Features.GetNamespaceResolver(), context.XmlReaderSettings, strictRelationshipFound))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,10 @@ public static XDocument ToFlatOpcDocument(this OpenXmlPackage openXmlPackage)
/// <returns>The corresponding <see cref="XElement"/>.</returns>
private static XElement GetContentsAsXml(IPackagePart part, HashSet<Uri> altChunkPartUris)
{
#if NET35
var settings = default(XmlReaderSettings);
#else
var settings = new XmlReaderSettings
{
DtdProcessing = DtdProcessing.Ignore,
};
#endif

if (part.ContentType.EndsWith("xml", StringComparison.Ordinal) &&
!altChunkPartUris.Contains(part.Uri))
Expand Down
17 changes: 0 additions & 17 deletions src/DocumentFormat.OpenXml.Framework/System/EnumHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,8 @@ namespace DocumentFormat.OpenXml
{
internal static class EnumHelper
{
#if NET35
public static bool TryParse<TEnum>(string? value, out TEnum result)
where TEnum : struct
{
try
{
result = (TEnum)Enum.Parse(typeof(TEnum), value);
return true;
}
catch (Exception)
{
result = default;
return false;
}
}
#else
public static bool TryParse<TEnum>(string? value, out TEnum result)
where TEnum : struct
=> Enum.TryParse(value, out result);
#endif
}
}
Loading