Skip to content

[Feature Request] Add support for AllowUnsafeBlocks in properties #10174

@andywiecko

Description

@andywiecko

Hi,
I would like to request a feature enhancement to add support for the "AllowUnsafeBlocks" within the "properties" section of docfx.json.

According to the documentation, the "properties" section:

Specifies an optional set of MSBuild properties used when interpreting project files. These are the same properties that are passed to MSBuild via the /property:name=value command line argument.

However, it seems that "AllowUnsafeBlocks" is currently not supported. From my understanding, adding support for this would require a small modification in the following file:

private static CS.CSharpParseOptions GetCSharpParseOptions(IDictionary<string, string> msbuildProperties)
{
var preprocessorSymbols = (msbuildProperties.TryGetValue("DefineConstants", out var defineConstants))
? defineConstants.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
: null;
return new CS.CSharpParseOptions(preprocessorSymbols: preprocessorSymbols);
}

Here’s a minimal working example that demonstrates the issue:

  • Program.cs
namespace Test
{
    public static class Program
    {
        public static unsafe void Main() { }
    }
}
  • docfx.json
{
  "metadata": [
    {
      "src": [{"src": "./", "files": ["Program.cs"]}],
      "dest": "api",
      "properties": { "AllowUnsafeBlocks": true }
    }
  ]
}

Expected behavior:

The api documentation should generate correctly without any errors or warnings.

Current behavior:

The build fails with errors/warnings, (unless one set "allowCompilationErrors": true).


Thank you for considering this request. I believe it would be a valuable addition.

Best,
Andrzej

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions