Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

We are pleased to announce the release of .NET 11 Preview 5. Follow the main announcement and blog announcement.

Browse the release notes for a full list of improvements in this release:

Get started

To get started with .NET 11, install the .NET 11 SDK.

If you're on Windows using Visual Studio, we recommend installing the latest Visual Studio 2026 Insiders. You can also use Visual Studio Code and the C# Dev Kit extension with .NET 11.

You must be logged in to vote

Replies: 2 comments · 2 replies

Comment options

@jjonescz trying out the #:ref directive but it's not working as expected on .NET 11 preview 5

https://github.com/dotnet/core/blob/main/release-notes/11.0/preview/preview5/sdk.md#file-based-apps-can-reference-other-c-files

helper.cs definition:

#:package WeihanLi.Core@1.0.90
using static WeihanLi.Common.Helpers.ConsoleHelper;

public static class Helper
{
    public static void WriteToConsole(string message)
    {
        Console.WriteLine(message);
    }

    public static void Print(string message)
    {
        WriteLineWithColor(message, ConsoleColor.Green);
    }
}

hello2.cs

#!/usr/bin/env dotnet
#:ref helper.cs

Helper.WriteToConsole("Hello, World!");

Helper.Print("Hello, World!");

got Program does not contain a static 'Main' method suitable for an entry point error as below:

> dotnet hello2.cs -v=diag
Restore complete (0.3s)
    Determining projects to restore...
    All projects are up-to-date for restore.
    info NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  helper.cs net11.0 failed with 1 error(s) (0.2s)
    CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point

Build failed with 1 error(s) in 1.2s

The build failed. Fix the build errors and run again.

it works when using #:include, is there anything I missed?

You must be logged in to vote
2 replies
@ufcpp
Comment options

While #:include A.cs is equivalent to <Compile Include="A.cs" />, #:ref is equivalent to <ProjectReference Include="A.csproj"/> after running dotnet build A.cs, right?
The issue with your code is that dotnet build helpler.cs fails, I guess. Currently, dotnet build for file-based apps without a Main method requires a little extra work. I think it should work if you add #:property OutputType=Library to helper.cs.

@WeihanLi
Comment options

@ufcpp thanks, it works when adding #:property OutputType=Library to helper.cs

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
📣
News
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.