Repository navigation
IT CSharp Directive Reference
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
La direttiva script aggiunge un assembly gestito già pronto per la compilazione dello script. La libreria deve esistere nel percorso specificato.
Salvare questo esempio separatamente come Example.csx. Eseguirlo indipendentemente dagli altri esempi di questa pagina.
Example.csx:
#r "Library.dll"
UO.Print(Demo.Number.Value.ToString());Library.cs:
// PROJECT-EXAMPLE
namespace Demo; public static class Number { public static int Value => 7; }Library.csproj:
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net10.0</TargetFramework><EnableDefaultCompileItems>false</EnableDefaultCompileItems></PropertyGroup><ItemGroup><Compile Include="Library.cs" /></ItemGroup></Project>dotnet build Library.csproj -o .Risultato:
7
#r "path/Library.dll"Innanzitutto, salva i file della libreria elencati ed esegui una build dotnet .csproj. #r percorsi sono forniti per Debug/net10.0. Per NuGet o un insieme di dipendenze, è più conveniente utilizzare immediatamente lo scenario .csproj con PackageReference.
#r "ApiLibrary/bin/Debug/net10.0/ApiLibrary.dll"
UO.Print(Demo.Tools.Double(4).ToString());File ApiLibrary/ApiLibrary.csproj:
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net10.0</TargetFramework></PropertyGroup></Project>File ApiLibrary/Tools.cs:
namespace Demo; public static class Tools { public static int Double(int value) => value * 2; }#r "Models/bin/Debug/net10.0/Models.dll"
Demo.Point point = new(2, 3);
UO.Print((point.X + point.Y).ToString());File Models/Models.csproj:
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net10.0</TargetFramework></PropertyGroup></Project>File Models/Point.cs:
namespace Demo; public readonly record struct Point(int X, int Y);Fonte ufficiale: Microsoft Impara.
ClassicUO — Bad Newbie & C# Scripts IDE