add support for userdev launch in ide
All checks were successful
Build / Compute Version (push) Successful in 8s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 4m5s
Build / Build Nuget package (NuGet) (push) Successful in 4m8s
Build / Build Nuget package (SharedCringe) (push) Successful in 4m9s
Build / Build Nuget package (CringePlugins) (push) Successful in 4m30s
Build / Build Launcher (push) Successful in 5m22s

add template for user plugins
This commit is contained in:
zznty
2025-07-07 02:44:02 +07:00
parent 7c236355d4
commit f238b52f95
16 changed files with 782 additions and 35 deletions

View File

@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<!-- This property tells MSBuild where the root folder of the package's build assets should be. Because we are not a library package, we should not pack to 'lib'. Instead, we choose 'tasks' by convention. -->
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
<!-- NuGet does validation that libraries in a package are exposed as dependencies, but we _explicitly_ do not want that behavior for MSBuild tasks. They are isolated by design. Therefore we ignore this specific warning. -->
<NoWarn>NU5100</NoWarn>
<DebugType>embedded</DebugType>
<IsPackable>true</IsPackable>
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.0.0" PrivateAssets="all" />
<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Content Include="build\CringePlugins.MSBuild.targets">
<PackagePath>build\</PackagePath>
</Content>
<Content Include="build\CringePlugins.MSBuild.props">
<PackagePath>build\</PackagePath>
</Content>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,86 @@
using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Win32;
namespace CringePlugins.MSBuild;
public class GenerateRunConfig : Task
{
[Required] public required string RunConfigPath { get; set; }
[Required] public required string ProjectName { get; set; }
private const string RunConfigTemplate = """
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"$projectName$ Dev Client": {
"commandName": "Executable",
"executablePath": "BootstrapExecutablePathPlaceholder",
"commandLineArgs": "\"GameExecutablePathPlaceholder\"",
"environmentVariables": {
"DOTNET_BOOTSTRAP_ENTRYPOINT": "CringeLauncher.UserDev.UserDevLauncher, CringeLauncher",
"DOTNET_USERDEV_RUNDIR": "data",
"DOTNET_USERDEV_PLUGINDIR": "."
}
}
}
}
""";
public override bool Execute()
{
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
{
Log.LogError("Only windows is supported");
return false;
}
// branch off so jit wont notice in case Win32 package is missing from sdk distribution on non-windows platforms
// too lazy to test if it actually is missing
return ExecuteInternal();
}
private bool ExecuteInternal()
{
string? GetInstallLocation(RegistryKey baseKey, string subKey)
{
using var key = baseKey.OpenSubKey(subKey);
return key?.GetValue("InstallLocation") as string;
}
var gamePath = GetInstallLocation(Registry.LocalMachine,
@"Software\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 244850");
var bootstrapPath = GetInstallLocation(Registry.CurrentUser,
@"Software\Microsoft\Windows\CurrentVersion\Uninstall\CringeLauncher");
if (string.IsNullOrEmpty(gamePath))
{
Log.LogError("Failed to find Space Engineers install location");
return false;
}
if (string.IsNullOrEmpty(bootstrapPath))
{
Log.LogError("Failed to find CringeLauncher install location");
return false;
}
gamePath = Path.Combine(gamePath, @"Bin64\SpaceEngineers.exe").Replace(@"\", @"\\");
bootstrapPath = Path.Combine(bootstrapPath, @"current\CringeBootstrap.exe").Replace(@"\", @"\\");
var runConfigText = RunConfigTemplate
.Replace("BootstrapExecutablePathPlaceholder", bootstrapPath)
.Replace("GameExecutablePathPlaceholder", gamePath)
.Replace("$projectName$", ProjectName);
var runConfigDir = Path.GetDirectoryName(RunConfigPath);
if (runConfigDir is not null && !Directory.Exists(runConfigDir))
Directory.CreateDirectory(runConfigDir);
File.WriteAllText(RunConfigPath, runConfigText);
return true;
}
}

View File

@@ -0,0 +1,14 @@
<Project>
<PropertyGroup>
<!--The folder where the custom task will be present. It points to inside the NuGet package. -->
<CustomTasksFolder>$(MSBuildThisFileDirectory)..\tasks\netstandard2.0</CustomTasksFolder>
<!--Reference to the assembly which contains the MSBuild Task-->
<CustomTasksAssembly>$(CustomTasksFolder)\$(MSBuildThisFileName).dll</CustomTasksAssembly>
</PropertyGroup>
<UsingTask TaskName="$(MSBuildThisFileName).GenerateRunConfig" AssemblyFile="$(CustomTasksAssembly)" />
<PropertyGroup>
<RunConfigPath Condition="'$(RunConfigPath)' == ''">$(ProjectDir)Properties\launchSettings.json</RunConfigPath>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,9 @@
<Project>
<Target Name="_GenerateRunConfig" AfterTargets="CollectPackageReferences" Condition=" '$([System.OperatingSystem]::IsWindows())' == 'True' ">
<GenerateRunConfig RunConfigPath="$(RunConfigPath)" ProjectName="$(MSBuildProjectName)" />
</Target>
<Target Name="AfterClean">
<Delete Files="$(RunConfigPath)" ContinueOnError="true" />
</Target>
</Project>