pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.3k stars 332 forks source link

Visual Studio 2022 build fails when loading plugins / commands w/o AddInId #1984

Closed eisaac-gs closed 11 months ago

eisaac-gs commented 11 months ago

Describe the bug Visual Studio fails to launch Revit 2023 when pyRevit is installed, hitting an error in the following class:

using System.Xml;
using pyRevitLabs.Common.Extensions;

namespace pyRevitLabs.TargetApps.Revit
{
    public class RevitAddonManifest
    {
        public string FilePath { get; set; }

        public string Name { get; set; }

        public string Assembly { get; set; }

        public string AddInId { get; set; }

        public string FullClassName { get; set; }

        public string VendorId { get; set; }

        public RevitAddonManifest(string manifestFile)
        {
            FilePath = manifestFile;
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(manifestFile);
            Name = xmlDocument.DocumentElement.SelectSingleNode("/RevitAddIns/AddIn/Name").InnerText;
            Assembly = xmlDocument.DocumentElement.SelectSingleNode("/RevitAddIns/AddIn/Assembly").InnerText.NormalizeAsPath();
            AddInId = xmlDocument.DocumentElement.SelectSingleNode("/RevitAddIns/AddIn/AddInId").InnerText;
            FullClassName = xmlDocument.DocumentElement.SelectSingleNode("/RevitAddIns/AddIn/FullClassName").InnerText;
            VendorId = xmlDocument.DocumentElement.SelectSingleNode("/RevitAddIns/AddIn/VendorId").InnerText;
        }
    }
}

where AddInId = xmlDocument.DocumentElement.SelectSingleNode("/RevitAddins/Addin/AddinId").InnerText; reports a System.NullReferenceException, determined via inspection, for plugins that have a ClientId, but not an AddInId. One such addin is the Autodesk.BatchPrint.addin, found @ C:\ProgramData\Autodesk\Revit\Addins\2020 for me.

Autodesk.BatchPrint.addin

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
  <AddIn Type="Application">
    <Name>Batch Print Application</Name>
    <Assembly>C:\Program Files\Autodesk\Batch Print for Revit 2020\BatchPrint.dll</Assembly>
    <ClientId>9d508589-48b6-4ff6-a50d-d16d77c585a1</ClientId>
    <FullClassName>Revit.PrintHarness.PrintHarnessApplication</FullClassName>
    <VendorId>ADSK</VendorId>
    <VendorDescription>Autodesk, subscription.autodesk.com</VendorDescription>
  </AddIn>
</RevitAddIns>

Revit 2023 launches normally when PyRevit is installed. Visual Studio can launch Revit for testing .NET plugins when pyRevit isn't installed. Previously, I was able to launch Revit via Visual Studio w/ pyRevit installed, but currently trying to launch Revit via Visual Studio when pyRevit is installed fails.

To Reproduce Steps to reproduce the behavior:

  1. Setup a .NET plugin for Revit in Visual Studio, following Autodesk's documentation
  2. Install pyRevit
  3. Attempt to launch in debug
  4. See error

Expected behavior Visual Studio should be able to launch Revit for testing .NET plugins while pyRevit is installed.

Screenshots N/A

Desktop (please complete the following information):

pyRevit version 4.8.13.23182 installed via installer Visual Studio Professional, version 17.7.1 Revit, version 23.1.10.4, 20221122_1550(x64), 2023.1.1

pyrevit env

==> Attachments
Unknown | Product: "2023.1.1" | Manifest: "C:\ProgramData\Autodesk\Revit\Addins\2023\pyRevit.addin"
Unknown | Product: "Autodesk Revit 2022" | Manifest: "C:\ProgramData\Autodesk\Revit\Addins\2022\pyRevit.addin"
Unknown | Product: "2021.1.7" | Manifest: "C:\ProgramData\Autodesk\Revit\Addins\2021\pyRevit.addin"
Unknown | Product: "2020.2.0" | Manifest: "C:\ProgramData\Autodesk\Revit\Addins\2020\pyRevit.addin"
...
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
2023.1.1 | Version: 23.1.10.4 | Build: 20221122_1550(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2023\"
Autodesk Revit 2022 | Version: 22.1.50.17 | Build: 20230915_1530(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2022\"
2021.1.7 | Version: 21.1.70.21 | Build: 20220517_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2021\"
2020.2.0 | Version: 20.2.90.12 | Build: 20220517_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020\"
==> Running Revit Instances
PID: 28216 | 2023.1.1 | Version: 23.1.10.4 | Build: 20221122_1550(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2023"
...
Microsoft Windows 10 [Version 10.0.19045]
Executing User: NASH\xxxxxx
Active User: NASH\xxxxxx
Admin Access: No
%APPDATA%: "C:\Users\xxxxxx\AppData\Roaming"
Latest Installed .Net Framework: 4.8
Installed .Net Target Packs: v4.0 v4.5 v4.5.1 v4.5.2 v4.6 v4.6.1 v4.7.2 v4.8 v4.8.1 v4.X
Installed .Net-Core Target Packs: v7.0.400
pyRevit CLI v4.8.13.23182+2215

some information about my employer's internal setup was ommitted

Additional context I've asked on Autodesk's forum, and checked the docs, but haven't found any info to narrow down which of the three programs, if any, is making an incorrect assumption.

jmcouffin commented 11 months ago

That may help clarify https://spiderinnet.typepad.com/blog/2011/09/deploy-install-manifest-clientid-and-addin.html

eisaac-gs commented 11 months ago

@jmcouffin - that is helpful - would this suggest that RevitAddons.cs should also support both AddInId & ClientId (since both are accepted in the manifest)?

It seems to expect AddInId, and error if it finds ClientId.

jmcouffin commented 11 months ago

@MYu1Gpzumr if you feel up to the task of understanding and fixing the thing, please have a go and make a PR against the develop branch

eisaac-gs commented 11 months ago

For posterity - got an answer from Autodesk as well:

ClientId is an obsolete name for AddInId. It is obviously still supported, silently, und the hood, but no longer documented... The two are interchangeable.

Source