mrlacey / Rapid-XAML-Toolkit

A collection of tools to accelerate XAML development within Visual Studio. These include XAML analysis, XAML generations, plus templates and helpers.
https://marketplace.visualstudio.com/items?itemName=MattLaceyLtd.RapidXamlToolkit
Other
670 stars 43 forks source link

Automatic triggering of custom analyzer #505

Open YakupIpek21 opened 2 years ago

YakupIpek21 commented 2 years ago

Question Is there a way to automatically trigger the custom analyzer when a project containing a xaml is built? Not only when the file is saved.

Desired Behaviour So any project referencing a custom analyzer should automatically analyze its existing Xaml files.

mrlacey commented 2 years ago

Yes, add this NuGet package to the project.

It adds a build step that runs the analysis. The intention is to allow you to have XAML analysis of a project even if the extension is not installed. (Such as on a build server 😉)

Note that the currently available version also suffers from the issue identified in #503 and so a new version of the RapidXaml.BuildAnalysis package is also needed.

YakupIpek21 commented 2 years ago

I see, thank you very much for the explanation

mrlacey commented 2 years ago

Version 0.13.0 of this NuGet package is now available and fixes the issue noted in #503 Example: image

PLEASE NOTE. This currently only works with projects that use the old internal structure. It does not yet work with SDK-style projects (As you'll get if you create a project targeting .NET5 or 6. The changes to support SDK style projects is being tracked separately in #408

mrlacey commented 2 years ago

If you have any problems, comments, or suggestions please raise another issue. If you love it, please leave a rating/review or consider sponsorship :smile:

YakupIpek21 commented 2 years ago

After having added the RapidXaml.BuildAnalysis nuget package to the project which contains the xaml files, it does not produce any warnings when the project is built in VisualStudio 19

Expected Behaviour When building a project which contains xaml files, the analysis should be triggered and warnings should be displayed

To reproduce

  1. Generate a custom analyzer image

  2. Add the project as a reference to the project containing xaml files (let's denote it as project A)

  3. Add the RapidXaml.BuildAnalysis nuget package (Version 0.13.0) to the project A

  4. In project A add a TextBlock Tag without the IsEnabled Attribute, save the file

  5. Enable in the options the Enable Custom Analysis menu

  6. When a warning is shown then restart VS19, so that no warning is shown, now build project A

  7. In my case no warning is shown in VS19

mrlacey commented 2 years ago

After having added the RapidXaml.BuildAnalysis nuget package to the project which contains the xaml files, it does not produce any warnings when the project is built in VisualStudio 19

What type of project are you using? Can you share a complete reproduction project, not just a partial description.

Also, please note, from above:

PLEASE NOTE. This currently only works with projects that use the old internal structure. It does not yet work with SDK-style projects (As you'll get if you create a project targeting .NET5 or 6.) The changes to support SDK style projects is being tracked separately in https://github.com/mrlacey/Rapid-XAML-Toolkit/issues/408

YakupIpek21 commented 2 years ago

Yes sure. The following reproduction steps refer to Visual Studio 2019 Version 16.11.5

  1. Via the Custom Rapid XAML Analyzer project template I am creating a custom analyzer with the following content image
  2. In the same solution I am creating a WPF-App with the target framework .Net Core 3.1
  3. The analyzer from step 1 is added as a reference to the WPF-app
  4. The RapidXaml.BuildAnalysis nuget package (Version 0.13.0) is added via the nuget manager to the WPF-app
  5. The menu entry Enable Custom Analysis is enabled
  6. In the WPF-app MainWindow.xaml file I added a TextBlock tag within the Grid tag and saved the xaml file
  7. I restart VS19, since in step 6 the analyzer is triggered through the saving
  8. I close all tabs in VS19 and build the WPF-app
  9. When I check for the warnings nothing is displayed
  10. When I open the MainWindow.xaml the warning is shown (not always)

Expected Behaviour When building the project in Visual Studio 2019 the warnings should be displayed in the Error List Window without needing to open or saving the xaml file in Visual Studio 2019.

mrlacey commented 2 years ago

Unfortunately, WPF with .Net Core 3.1 also uses an SDK style project format and so the BuildAnalysis doesn't know which files to check. This is why it is not reporting anything.

I'll look to prioritize supporting this. (Very few people have been using RXT with WPF projects and so this is a good opportunity to improve this experience.)