0

I have the latest Visual Studio Preview and the latest .Net preview SDK installed and the project builds, with the code I want to try and the correct version of .Net.

But no new code is executed so I am unable to use the latest C# feature. Which in this instance is the interceptors in C#12.

The answer showed in the post below says to use the latest roslyn complier branch from git hub and "run the code in that". But how do I actually do that?

Orignal Answer

Edit: Interceptor code:

public static class GeneratedCode
{
    [InterceptsLocation("""C:\Users\Admin\source\repos\PreviewNet8\Program.cs""", line: 5, character: 9)] // refers to the call at (L1, C1)
    public static void InterceptorMethod(this Example example, string param)
    {
        Console.WriteLine($"Hello strange new {param}");
    }
}

    <PropertyGroup>
      <OutputType>Exe</OutputType>
      <TargetFramework>net8.0</TargetFramework>
      <ImplicitUsings>enable</ImplicitUsings>
      <Nullable>enable</Nullable>
      <PublishAot>true</PublishAot>
      <InvariantGlobalization>true</InvariantGlobalization>
      <LangVersion>preview</LangVersion>
      <Features>InterceptorsPreview</Features>
   </PropertyGroup>
Debugs
  • 9
  • 3

0 Answers0