peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.36k stars 201 forks source link

Installing Peachpie .NET templates doesn't work #970

Closed KygekDev closed 3 years ago

KygekDev commented 3 years ago

Issue

When i ran dotnet new -i Peachpie.Templates::*, it just showed a list of available default built-in templates in .NET Core SDK:

Template Name                                 Short Name           Language        Tags
--------------------------------------------  -------------------  --------------  ----------------------
Console Application                           console              [C#],F#,PHP,VB  Common/Console
Class library                                 classlib             [C#],F#,PHP,VB  Common/Library
WPF Application                               wpf                  [C#],VB         Common/WPF
WPF Class library                             wpflib               [C#],VB         Common/WPF
WPF Custom Control Library                    wpfcustomcontrollib  [C#],VB         Common/WPF
WPF User Control Library                      wpfusercontrollib    [C#],VB         Common/WPF
Windows Forms App                             winforms             [C#],VB         Common/WinForms
Windows Forms Control Library                 winformscontrollib   [C#],VB         Common/WinForms
Windows Forms Class Library                   winformslib          [C#],VB         Common/WinForms
Worker Service                                worker               [C#],F#         Common/Worker/Web
MSTest Test Project                           mstest               [C#],F#,VB      Test/MSTest
NUnit 3 Test Item                             nunit-test           [C#],F#,VB      Test/NUnit
NUnit 3 Test Project                          nunit                [C#],F#,VB      Test/NUnit
xUnit Test Project                            xunit                [C#],F#,VB      Test/xUnit
Razor Component                               razorcomponent       [C#]            Web/ASP.NET
Razor Page                                    page                 [C#]            Web/ASP.NET
MVC ViewImports                               viewimports          [C#]            Web/ASP.NET
MVC ViewStart                                 viewstart            [C#]            Web/ASP.NET
Blazor Server App                             blazorserver         [C#]            Web/Blazor
Blazor WebAssembly App                        blazorwasm           [C#]            Web/Blazor/WebAssembly
ASP.NET Core Empty                            web                  [C#],F#,PHP     Web/Empty
ASP.NET Core Web App (Model-View-Controller)  mvc                  [C#],F#         Web/MVC
ASP.NET Core Web App                          webapp               [C#]            Web/MVC/Razor Pages
ASP.NET Core with Angular                     angular              [C#]            Web/MVC/SPA
ASP.NET Core with React.js                    react                [C#]            Web/MVC/SPA
ASP.NET Core with React.js and Redux          reactredux           [C#]            Web/MVC/SPA
Razor Class Library                           razorclasslib        [C#]            Web/Razor/Library
ASP.NET Core Web API                          webapi               [C#],F#         Web/WebAPI
ASP.NET Core gRPC Service                     grpc                 [C#]            Web/gRPC
dotnet gitignore file                         gitignore                            Config
global.json file                              globaljson                           Config
NuGet Config                                  nugetconfig                          Config
Dotnet local tool manifest file               tool-manifest                        Config
Web Config                                    webconfig                            Config
Solution File                                 sln                                  Solution
Protocol Buffer File                          proto                                Web/gRPC

Examples:
    dotnet new mvc --auth Individual
    dotnet new web
    dotnet new --help
    dotnet new web --help

System Information

jakubmisek commented 3 years ago

thank you for the issue. Is it the whole output? There suppose to be something like

The following template packages will be installed:
   Peachpie.Templates

at the beginning of the output. Ref https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-new-install

KygekDev commented 3 years ago

Is it the whole output?

Yes, there is no other outputs.

There suppose to be something like

The following template packages will be installed:
   Peachpie.Templates

at the beginning of the output.

No, there is no in mine.

jakubmisek commented 3 years ago

does this work in your case?

dotnet new --install Peachpie.Templates::*
KygekDev commented 3 years ago

No it doesn't.

jakubmisek commented 3 years ago

this is really weird, according to https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-new-install I'm not sure if it's possible for dotnet to ignore an argument (--install).

The output you have corresponds to the command

dotnet new

without arguments

jakubmisek commented 3 years ago

Oh - I see it. You have it right there:

Console Application                           console              [C#],F#,PHP,VB  Common/Console
Class library                                 classlib             [C#],F#,PHP,VB  Common/Library

PHP is there. So you have the templates installed.

KygekDev commented 3 years ago

Okay, so I ran dotnet new console --language php and it worked. But, when I run dotnet restore or dotnet run, I get these errors:

error NU1100: Unable to resolve 'Peachpie.App (>= 1.0.6)' for '.NETFramework,Version=v5.0'.
error NU1100: Unable to resolve 'Peachpie.App (>= 1.0.6)' for '.NETFramework,Version=v5.0/win7-x86'.

I think the Peachpie SDK is not installed or configured properly. What can I do to fix it?

jakubmisek commented 3 years ago

Good. What is the content of the created .msbuildproj file?

KygekDev commented 3 years ago

Here's it.

<Project Sdk="Peachpie.NET.Sdk/1.0.6">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <StartupObject>program.php</StartupObject>
    <Description>Simpliest PHP project for .NET Core, a console application.</Description>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**/*.php" />
  </ItemGroup>

</Project>
jakubmisek commented 3 years ago

Seems you might not have .NET Sdk 5.0 installed (https://dotnet.microsoft.com/download)

What is your

dotnet --version

?

KygekDev commented 3 years ago

It prints 5.0.301, as mentioned above.

EDIT: This might happen because I accidentally run this command and it deleted all files inside %userprofile%\.nuget: https://stackoverflow.com/a/34935038. I've tried reinstalling both .NET SDK 5 and Core SDK 3.1, but it didn't solved the issue.

jakubmisek commented 3 years ago

It prints 5.0.301, as mentioned above.

right sorry

EDIT: This might happen because I accidentally run this command and it deleted all files inside %userprofile%\.nuget https://stackoverflow.com/a/34935038

I was just about to ask if you nuget.org in your nuget sources

jakubmisek commented 3 years ago

Is nuget.org in there?

dotnet nuget list source
KygekDev commented 3 years ago

Is nuget.org in there?

dotnet nuget list source

No.

jakubmisek commented 3 years ago

try the following

dotnet nuget add source https://api.nuget.org/v3/index.json -n "nuget.org source"
KygekDev commented 3 years ago

try the following

dotnet nuget add source https://api.nuget.org/v3/index.json -n "nuget.org source"

It worked after I ran dotnet restore. But I got another error when I run dotnet run:

C:\Program Files\dotnet\sdk\5.0.301\Microsoft.Common.CurrentVersion.targets(1216,5): error MSB3971: The reference assemblies for ".NETFramework,Version=v5.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK. [C:\Files\phpexe\phpexe.msbuildproj]

The build failed. Fix the build errors and run again.
jakubmisek commented 3 years ago

Seems like a bit broken .NET installation to me (like at https://github.com/dotnet/core/issues/6256 but there is no real solution for Windows).

In your case, the SDK comes with Visual Studio probably, I would try running the Visual Studio Installer and see if it tells there is an update, maybe it fixes the problem.

jakubmisek commented 3 years ago

Same as https://stackoverflow.com/a/65740309/601646

KygekDev commented 3 years ago

In your case, the SDK comes with Visual Studio probably

No, I installed the standalone version of .NET SDK. Actually, I installed Visual Studio before, but then I removed Visual Studio completely before installing .NET SDK.

jakubmisek commented 3 years ago

Seems it's still using the removed VS version tho.

I would guess there will be some Sdks in your Windows Settings / Apps & Features ? Namely "Microsoft .NET SDK 5.0.301 (x64) from Visual Studio". Try Uninstalling it from there, eventually you can uninstall other .NET SDK 5.0.xxx if there's more of them.

KygekDev commented 3 years ago

I would guess there will be some Sdks in your Windows Settings / Apps & Features ? Namely "Microsoft .NET SDK 5.0.301 (x64) from Visual Studio".

I can see there are only 2 installed .NET SDKs as of in the Settings: image

jakubmisek commented 3 years ago

does reinstalling .NET SDK help?

KygekDev commented 3 years ago

I managed to figure out and solve the issue. So, the issue is with the environment variable. I'll explain further soon.

jakubmisek commented 3 years ago

@KygekDev awesome, i'm interested

KygekDev commented 3 years ago

I will explain it now.

So, I remembered that I set a MSBuildSDKsPath environment variable while figuring out a solution for the issue. Then I checked the environment variable. It was set C:\Program Files\dotnet\sdk\3.1.410\Sdks. Then I changed it to C:\Program Files\dotnet\sdk\5.0.301\Sdks, and it solved the issue.

jakubmisek commented 3 years ago

makes sense, thanks for sharing the experience with us!

KygekDev commented 3 years ago

I need one more help.

When I ran dotnet-warp -l aggressive --verbose flag, it failed, with an output:

Running AddLinkerPackage...
Running dotnet add package --source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json ILLink.Tasks -v 0.1.5-preview-1841731
  Determining projects to restore...
  Writing C:\Users\COMPUTER\AppData\Local\Temp\tmpEF02.tmp
info : Adding PackageReference for package 'ILLink.Tasks' into project 'C:\Files\phpexe\phpexe.csproj'.
info : Restoring packages for C:\Files\phpexe\phpexe.csproj...
error: Unable to load the service index for source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json.
error:   The SSL connection could not be established, see inner exception.
error:   The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

I get an SSL error when opening https://dotnet.myget.org/F/dotnet-core/api/v3/index.json in a browser. So, is there a way to remove the package in the build process?

jakubmisek commented 3 years ago

@KygekDev right, "dotnet-warp" uses https://dotnet.myget.org/ NuGet source which has an invalid SSL certificate. Thus the command fails. I don't see any option where you could override this NuGet source, seems it is hard-coded in there.

I'm not well experienced with "dotnet-warp". Since it is a 3rd party tool, I'd recommend posting an issue at https://github.com/Hubert-Rybak/dotnet-warp

KygekDev commented 3 years ago

Okay, thanks for your fast response!

jakubmisek commented 3 years ago

I'm glad you got it working!

I hope the last issue will get resolved as well.

KygekDev commented 3 years ago

Looks like the dotnet-warp repository has been archived and left unmaintained for more than a year and a half.

jakubmisek commented 3 years ago

I'm afraid so. Although for trimming the resulting assembly, there are built-in features in .NET 5.0 itself - https://devblogs.microsoft.com/dotnet/app-trimming-in-net-5/