Repository navigation
FR CSharp Directive Reference
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
La directive script ajoute un assembly géré prêt à l'emploi pour la compilation de scripts. La bibliothèque doit exister dans le chemin spécifié.
Enregistrez cet exemple séparément dans Example.csx. Exécutez-le indépendamment des autres exemples de cette page.
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 .Résultat:
7
#r "path/Library.dll"Tout d'abord, enregistrez les fichiers de bibliothèque répertoriés et exécutez une version dotnet pour ceux-ci .csproj. #r chemins sont donnés pour Debug/net10.0. Pour NuGet ou un ensemble de dépendances, il est plus pratique d'utiliser immédiatement le scénario .csproj avec PackageReference.
#r "ApiLibrary/bin/Debug/net10.0/ApiLibrary.dll"
UO.Print(Demo.Tools.Double(4).ToString());Fichier ApiLibrary/ApiLibrary.csproj :
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net10.0</TargetFramework></PropertyGroup></Project>Fichier 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());Fichier Models/Models.csproj :
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net10.0</TargetFramework></PropertyGroup></Project>Fichier Models/Point.cs :
namespace Demo; public readonly record struct Point(int X, int Y);Source officielle : Microsoft Apprendre.
ClassicUO — Bad Newbie & C# Scripts IDE