BepInEx / BepInEx.Templates

A collection of dotnet templates for BepInEx
MIT License
17 stars 10 forks source link

.NET 8 SDK "Object reference not set..." when trying to use template #8

Closed akarnokd closed 4 months ago

akarnokd commented 11 months ago

With .NET 8 out, the usual way of using the template results in a not too detailed error message.

Can you look into the compatibility issue?

Issue

C:\temp\1>dotnet new bepinex5plugin -n MyModNameHere -T netstandard2.1 -U 2023.1.9
Template "BepInEx 5 Plugin Template" could not be created.
Failed to create template.
Details: Object reference not set to an instance of an object.

For details on the exit code, refer to https://aka.ms/templating-exit-codes#100

Yes, the template (1.4) is installed:

C:\temp\2>dotnet new -i BepInEx.Templates --nuget-source https://nuget.bepinex.dev/v3/index.json
Warning: use of 'dotnet new --install' is deprecated. Use 'dotnet new install' instead.
For more information, run:
   dotnet new install -h

The following template packages will be installed:
   BepInEx.Templates

BepInEx.Templates (version 1.4.0) is already installed, it will be replaced with latest version.
BepInEx.Templates::1.4.0 was successfully uninstalled.
Success: BepInEx.Templates::1.4.0 installed the following templates:
Template Name                            Short Name            Language  Tags
---------------------------------------  --------------------  --------  --------------------------------------
BepInEx 5 Plugin Template                bepinex5plugin        [C#]      BepInEx/BepInEx 5/Plugin
BepInEx 6 .NET Launcher Plugin Template  bep6plugin_netfx      [C#]      BepInEx/BepInEx 6/Plugin/.NET Launcher
BepInEx 6 Il2Cpp Plugin Template         bep6plugin_il2cpp     [C#]      BepInEx/BepInEx 6/Plugin/Il2Cpp
BepInEx 6 Unity Mono Plugin Template     bep6plugin_unitymono  [C#]      BepInEx/BepInEx 6/Plugin/Unity Mono

Workaround

C:\temp\1>dotnet new bepinex5plugin -n MyModNameHere -T netstandard2.1 -U 2023.1.9

Welcome to .NET 7.0!
---------------------
SDK Version: 7.0.404

Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
Learn about HTTPS: https://aka.ms/dotnet-https
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
The template "BepInEx 5 Plugin Template" was created successfully.
ManlyMarco commented 11 months ago

Shouldn't this be reported to .NET as a regression?

akarnokd commented 11 months ago

Alright, let's the :point_right: :point_left: begin.

https://github.com/dotnet/sdk/issues/36991

patrickdundas commented 11 months ago

@akarnokd I ran into this issue earlier today and resolved it by installing .NET 6 and uninstalling .NET 8 via Windows "Apps & Features" Visual Studio Modify Installation button, which allows you to uncheck .NET 8 to uninstall it via the Visual Studio Installer. Once this is uninstalled, you will see .NET 6 when running dotnet --version. Once that is done, use the dotnet new CLI to create from the template like usual. You may need to restart your computer / Visual Studio.

akarnokd commented 11 months ago

@patrickdundas I already had the workaround and wasn't looking for one. The issue at hand is why it broke with .NET 8 and if it's the template's fault or .NET 8's. Apparently, it's a bug with .NET 8.

Rubyboat1207 commented 10 months ago

In the meantime while .NET 8 can't be used to make the project. Here's the workaround I used that does not involve deleting .NET 8:

  1. run dotnet --list-sdks Here's what mine looked like:

    6.0.417 [C:\Program Files\dotnet\sdk]
    7.0.304 [C:\Program Files\dotnet\sdk]
    7.0.400 [C:\Program Files\dotnet\sdk]
    8.0.100-preview.7.23376.3 [C:\Program Files\dotnet\sdk]
  2. make this file and call it global.json in your current directory:

    {
    "sdk": {
        "version": "<dotnet 6 or 7 version>"
    }
    }

    mine looked like this:

    {
    "sdk": {
        "version": "7.0.400"
    }
    }
  3. then run the dotnet new as you would otherwise.

Hope this helps anyone

fhgaha commented 9 months ago

Instructions unclear.

  1. make this file and call it global.json in your current directory:

what is current directory? directory where i try to create my mod? shouldnt global.json be somewhere in dotnet directory?

  1. then run the dotnet new as you would otherwise.

You mean these commands from bepinex guide? dotnet new bep6plugin_unity_mono -n MyFirstPlugin -T <TFM> -U <Unity> dotnet restore MyFirstPlugin

LittleSaya commented 8 months ago

Instructions unclear.

  1. make this file and call it global.json in your current directory:

what is current directory? directory where i try to create my mod? shouldnt global.json be somewhere in dotnet directory?

  1. then run the dotnet new as you would otherwise.

You mean these commands from bepinex guide? dotnet new bep6plugin_unity_mono -n MyFirstPlugin -T <TFM> -U <Unity> dotnet restore MyFirstPlugin

I found a document about global.json

update: sorry I think I pasted a link in this comment before I submitted it...but I couldn't find that link now...

If I remember correctly, that document says dotnet will search for global.json in a hierarchical way up to the root of current driver. For example, if you run dotnet under C:\a\b\c\, the searching of global.json will be done in the following order:

  1. C:\a\b\c\global.json
  2. C:\a\b\global.json
  3. C:\a\global.json
  4. C:\global.json
Rubyboat1207 commented 7 months ago

Instructions unclear.

  1. make this file and call it global.json in your current directory:

what is current directory? directory where i try to create my mod? shouldnt global.json be somewhere in dotnet directory?

  1. then run the dotnet new as you would otherwise.

You mean these commands from bepinex guide? dotnet new bep6plugin_unity_mono -n MyFirstPlugin -T <TFM> -U <Unity> dotnet restore MyFirstPlugin

"current directory" meant wherever you planned on running dotnet new. so you could call that the root of your project folder

and yes i do mean that command.

jfmherokiller commented 6 months ago

for anyone coming upon this issue the simplest method is using the global.json file.

and unless there is a way to set it via some kind of environment variable or the like you must create it in the same directory you wish to store the project.

What that means is you want the file in the directory you are going to run a command like dotnet new bepinex5plugin -n OuterWildsTest

if you put the file in the correct location the command above will succeed and the resulting directory will look like

 OuterWildsTest
 global.json
ManlyMarco commented 4 months ago

Was this resolved by merging #12?

p4nu commented 4 months ago

Was this resolved by merging #12?

Yes, @ManlyMarco, but apparently the dotnet build fails with .net8.

ManlyMarco commented 4 months ago

That sounds like a different issue, closing this as resolved then.