Thursday, November 21, 2024

Open a web page when a project can't be built

When writing the Uno book, we wanted a way to have the project fail with a useful message if a required dependency hadn't also been set up correctly.

Below is what I came up with.


<Target Name="CheckForSfChart">
    <Exec Condition="!Exists('..\..\..\syncfusion-Uno.SfChart\Src\Syncfusion.SfChart.Uno.csproj')" Command="cmd.exe /c start https:////github.com/PacktPublishing/Creating-cross-platform-applications-with-Uno/tree/main/Chapter6/readme.md" />
    <Error Condition="!Exists('..\..\..\syncfusion-Uno.SfChart\Src\Syncfusion.SfChart.Uno.csproj')" Text="The SfChart project is also needed. See https://github.com/PacktPublishing/Creating-cross-platform-applications-with-Uno/tree/main/Chapter6/readme.md" />
  </Target>

See the real thing in GitHub.


If the required other project is missing, it:

  • Opens a webpage with more details.
  • Outputs a message with details in the build output.


Points of note:

  • Yes, msbuild will fail to compile the solution with missing project anyway. This is just additional info to help in debugging.
  • Repeated slashes in the url ("https:////" instead of "https://") due to them assumed to be being escaped
  • Because this call cmd.exe, it will only work on Windows.
  • Not a perfect solution but better than nothing.



Documenting this now before I forget.


0 comments:

Post a Comment

I get a lot of comment spam :( - moderation may take a while.