Nice3point / RevitTemplates

Templates for creating Revit add-ins
MIT License
208 stars 31 forks source link

Using the Build Project with multiple versions of Revit doesn't build with correct nuget package #40

Closed ktcondon closed 11 months ago

ktcondon commented 1 year ago

If you try to build revit versions R20-R24 with the build project and say you have your config set to Debug R22 (Can't have it set to Release when running the Build Project as that will cause issues with files being locked for the running process) then you run the Build project.

In your addin project you have conditional code based on the different versions of Revit so then when it goes to compile the R24 config of the addin it fails to compile because it believes it is referencing an older version of the Revit dlls. However the config is set to Release R24 for that addin and when I compile it manually in the Release R24 config it works. Its my understanding that when you run the Build project it compiles each project based on the passed in config not the config profile running the Build project.

To solve this I can run the build project with each different versions of Revit but I can't run it all at once.

What am I missing here?

ktcondon commented 1 year ago

Edit: I figured it out. Since I switched to MSBuild from DotNetBuild I had to explicitly tell nugut to restore the packages before it runs the build. This way you can run all configs of the Revit. I switch to MSBuild for building the projects as the newer DotNetBuild doesn't work with .resx files because the way serializable resources are handled changed from .net 48 framework to .net 7. You can add the System.Resources.Extensions to handle this issue, but that dll doesn't play nice with Revit. There might be ways around the dll hell issue would be open to comments.

` Target Compile => => .TriggeredBy(Clean) .Executes(() => { var projectFiles = Globbing.GlobFiles("./", "*/.csproj");

        foreach (var configuration in GlobBuildConfigurations())
            foreach (var project in projectFiles)
            {
                MSBuildTasks.MSBuild(settings => settings
                    .SetProjectFile(project)
                    .SetTargets("Restore")
                    .SetConfiguration(configuration)
                    .SetMSBuildPlatform(MSBuildPlatform.x64)
                    .SetVerbosity(MSBuildVerbosity.Minimal));

                MSBuildTasks.MSBuild(settings => settings
                    .SetConfiguration(configuration)
                    .SetMSBuildPlatform(MSBuildPlatform.x64)
                    .SetProjectFile(project)
                    .SetAssemblyVersion(Version)
                    .SetVerbosity(MSBuildVerbosity.Minimal));
            }
    });`

Posting the code here for anyone else who may find themselves in a similar position. Thanks to nicepoint for providing an amazing set of repositories to reference and use.

Nice3point commented 1 year ago

Hi @ktcondon )

You don't need to compile and run the Build project. Instead, you need to do another thing

  1. If you are using Rider, start Nuke from the startup configurations. It doesn't matter which build version you are running, DebugR20 or Release24. Nuke builds the project for all configurations

изображение

  1. If you use other IDEs (Visual Studio), write nuke in terminal and run it. изображение

MSBuild from DotNetBuild also does not need to be changed, the project is fully configured and works out of the box

ktcondon commented 1 year ago

I see I missed a very basic understanding of the nuke project. My apologies.

However while you are correct it works out of the box it still doesn't work when you are using .resx files in your visual studio projects. As you can see in the image below that by using the DotNetBuild it is requiring the use of System.Resources.Extensions. When you include that dll in your project it does compile but when you run Revit it fails to find the icons in the .resx file. Trying to resolve the assembly binding or use assembly redirects in the config file doesn't fix the issue with loading the dll into Revit.

MSBuild doesn't require this as has different handling for building .net framework projects.

image

Nice3point commented 1 year ago

Yes, you should probably use MsBuild for WinForms projects. Templates targeted for Wpf 😉 You can easily modify the code to suit your needs