AvaloniaUI / Avalonia.Markup.Declarative

Provides helpers for declarative ui in C#
374 stars 21 forks source link

avalonia-amd-gen doesn't read properties in csproj #68

Open philippelatulippe opened 1 month ago

philippelatulippe commented 1 month ago

When I run avalonia-amd-gen on a project created by Rider, I get the following error:

Packages found in the .csproj file:
An error occurred: '$(AvaloniaVersion)' is not a valid version string. (Parameter 'value')
   at NuGet.Versioning.NuGetVersion.Parse(String value)
   at AvaloniaExtensionGenerator.CsProjectTypesExtractor.GetAllDependencyPackages(String packageName, String packageVersion, String targetFramework) in C:\Projects\Avalonia\Avalonia.Markup.Declarative\src\AvaloniaExtensionGenerator\CsProjectTypesExtractor.cs:line 80
   at AvaloniaExtensionGenerator.CsProjectTypesExtractor.LoadTypesFromProject(String projectPath, String baseTypeNameToFilter, String[] ignoreAssemblies) in C:\Projects\Avalonia\Avalonia.Markup.Declarative\src\AvaloniaExtensionGenerator\CsProjectTypesExtractor.cs:line 147
   at AvaloniaExtensionGenerator.Program.Main(String[] args) in C:\Projects\Avalonia\Avalonia.Markup.Declarative\src\AvaloniaExtensionGenerator\Program.cs:line 73

It looks like the csproj file reader doesn't understand variables, since the variable AvaloniaVersion is definited in PropertyGroup.

gritsenko commented 1 month ago

@philippelatulippe can you share archive with the project folder here?

philippelatulippe commented 1 month ago

I can't share the whole project but I can certainly share the csproj:

csproj net8.0 enable enable 11.2.0-rc1 MainWindow.axaml Code
IvanJosipovic commented 1 month ago

@gritsenko, I'm starting to wonder if integrating the generation CLI into MSBuild would make it simpler. A Custom MSbuild step could get a list of all loaded libraries and that could be used to trigger the generation.

I use a MSBuild step here that runs after the ResolveReferences step. https://github.com/IvanJosipovic/KubernetesCRDModelGen/blob/86e5de4755a0263a5017a85896c30a1c5468c966/src/KubernetesCRDModelGen/KubernetesCRDModelGen.csproj#L31

gritsenko commented 3 weeks ago

@IvanJosipovic I thought about it as well, but we need to generate extensions before building step already, and even when project itself has errors and can't to be built. Do you think it is possible to use msbuild in this case? Or I misunderstanding how it works?

IvanJosipovic commented 3 weeks ago

@IvanJosipovic I thought about it as well, but we need to generate extensions before building step already, and even when project itself has errors and can't to be built. Do you think it is possible to use msbuild in this case? Or I misunderstanding how it works?

@gritsenko, I created an example PR, https://github.com/AvaloniaUI/Avalonia.Markup.Declarative/pull/70 Have a look, if its interesting, we can continue the work there. I believe we can also publish custom "MSBuild Target" as a part of the NuGet package to make it even simpler to use.