Why is Rider launching my application after building it?

I've been porting a large WPF C# application to Avalonia using Rider as the IDE. It's worked very successfully and Rider has proved to be an excellent tool. My problem is that there is a small section of functionality that I cannot currently migrate to Avalonia so I've created a small WPF application that communicates with the main application over RPC. Trouble is that every time I build the WPF application, Rider then launches it and I have to close it again. The main application launches the satellite application as it starts up. I have scanned the build configuration and I simply cannot see any option selected that should launch the application after build - any suggestions where I should be looking? The main application works fine - I build it and nothing is launched until I select the Run or Debug buttons…

Martin

0
7 comments

Hello Martin A Bradford,

Could you clarify how exactly you build the WPF application (Build Project/Build Solution/Build→Advanced Build Actions…) and check your .csproj to make sure that there are no build events related to project launch (Project Properties → Build Events)?

0

My .csproj file is this:
<Project Sdk="Microsoft.NET.Sdk">

   <PropertyGroup>
       <OutputType>WinExe</OutputType>
       <TargetFramework>net9.0-windows</TargetFramework>
       <RootNamespace>_101CatsScreen</RootNamespace>
       <Nullable>enable</Nullable>
       <ImplicitUsings>enable</ImplicitUsings>
       <UseWPF>true</UseWPF>
       <Platforms>AnyCPU;x64</Platforms>
       <ApplicationIcon>..\Avalonia101Cats\Assets\Google-Noto-Emoji-Animals-Nature-22221-cat.32.ico</ApplicationIcon>
   </PropertyGroup>

   <ItemGroup>
     <PackageReference Include="log4net" Version="3.0.3" />
     <PackageReference Include="StreamJsonRpc" Version="2.21.10" />
     <PackageReference Include="WPFMediaKit" Version="3.0.1" />
   </ItemGroup>

   <ItemGroup>
     <Compile Include="..\Avalonia101Cats\Models\IAppRPC.cs">
       <Link>Models\IAppRPC.cs</Link>
     </Compile>
   </ItemGroup>

   <ItemGroup>
     <None Include="..\Avalonia101Cats\Assets\Google-Noto-Emoji-Animals-Nature-22221-cat.32.ico">
       <Link>Google-Noto-Emoji-Animals-Nature-22221-cat.32.ico</Link>
     </None>
   </ItemGroup>

</Project>

The solution contains three projects (plus a fourth that is normally unloaded). One it a custom control library, the largest is the Avalonia application and the third is the small WPF application. Any build operation - the full solution or any of the individual projects - results in the WPF application being launched.

The solution file is :

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35521.163
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia101Cats", "Avalonia101Cats\Avalonia101Cats.csproj", "{1D4DDAE5-2608-4888-9846-D9EC37F26F41}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatMeterTest", "CatMeterTest\CatMeterTest.csproj", "{32B9CC45-95CA-475F-B89E-3B9D8C291CCB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatsControls", "CatsControls\CatsControls.csproj", "{5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "101CatsScreen", "101CatsScreen\101CatsScreen.csproj", "{375750A6-F9ED-43FF-8A27-2526ABC41DBB}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Debug|ARM64 = Debug|ARM64
        Debug|x64 = Debug|x64
        Debug|x86 = Debug|x86
        Release|Any CPU = Release|Any CPU
        Release|ARM64 = Release|ARM64
        Release|x64 = Release|x64
        Release|x86 = Release|x86
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Debug|Any CPU.ActiveCfg = Debug|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Debug|Any CPU.Build.0 = Debug|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Debug|ARM64.ActiveCfg = Debug|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Debug|ARM64.Build.0 = Debug|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Debug|x64.ActiveCfg = Debug|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Debug|x64.Build.0 = Debug|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Debug|x86.ActiveCfg = Debug|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Debug|x86.Build.0 = Debug|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Release|Any CPU.ActiveCfg = Release|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Release|Any CPU.Build.0 = Release|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Release|ARM64.ActiveCfg = Release|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Release|ARM64.Build.0 = Release|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Release|x64.ActiveCfg = Release|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Release|x64.Build.0 = Release|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Release|x86.ActiveCfg = Release|x64
        {1D4DDAE5-2608-4888-9846-D9EC37F26F41}.Release|x86.Build.0 = Release|x64
        {32B9CC45-95CA-475F-B89E-3B9D8C291CCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {32B9CC45-95CA-475F-B89E-3B9D8C291CCB}.Debug|ARM64.ActiveCfg = Debug|Any CPU
        {32B9CC45-95CA-475F-B89E-3B9D8C291CCB}.Debug|x64.ActiveCfg = Debug|Any CPU
        {32B9CC45-95CA-475F-B89E-3B9D8C291CCB}.Debug|x86.ActiveCfg = Debug|Any CPU
        {32B9CC45-95CA-475F-B89E-3B9D8C291CCB}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {32B9CC45-95CA-475F-B89E-3B9D8C291CCB}.Release|Any CPU.Build.0 = Release|Any CPU
        {32B9CC45-95CA-475F-B89E-3B9D8C291CCB}.Release|ARM64.ActiveCfg = Release|Any CPU
        {32B9CC45-95CA-475F-B89E-3B9D8C291CCB}.Release|x64.ActiveCfg = Release|Any CPU
        {32B9CC45-95CA-475F-B89E-3B9D8C291CCB}.Release|x86.ActiveCfg = Release|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Debug|ARM64.ActiveCfg = Debug|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Debug|ARM64.Build.0 = Debug|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Debug|x64.ActiveCfg = Debug|x64
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Debug|x64.Build.0 = Debug|x64
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Debug|x86.ActiveCfg = Debug|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Debug|x86.Build.0 = Debug|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Release|Any CPU.Build.0 = Release|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Release|ARM64.ActiveCfg = Release|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Release|ARM64.Build.0 = Release|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Release|x64.ActiveCfg = Release|x64
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Release|x64.Build.0 = Release|x64
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Release|x86.ActiveCfg = Release|Any CPU
        {5F31C958-3BE9-458D-B6CF-A38EDEAC67F2}.Release|x86.Build.0 = Release|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Debug|ARM64.ActiveCfg = Debug|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Debug|ARM64.Build.0 = Debug|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Debug|x64.ActiveCfg = Debug|x64
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Debug|x64.Build.0 = Debug|x64
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Debug|x86.ActiveCfg = Debug|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Debug|x86.Build.0 = Debug|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Release|Any CPU.Build.0 = Release|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Release|ARM64.ActiveCfg = Release|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Release|ARM64.Build.0 = Release|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Release|x64.ActiveCfg = Release|x64
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Release|x64.Build.0 = Release|x64
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Release|x86.ActiveCfg = Release|Any CPU
        {375750A6-F9ED-43FF-8A27-2526ABC41DBB}.Release|x86.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
EndGlobal

 

 

 

0

OK - I've worked out why it's happening - still need to understand how to stop it…

It's caused by the AvaloniaRider plugin. This provides support for Avalonia development including a screen layout preview and it is this preview that is causing the problem. It seems that it partially executes the application in order to generate the image of the screen and, in the case of my application, that partial application triggers the execution of the other application. If I don't have the main window of my application open in Rider when I build, the secondary application is not executed.

0

… and a solution is to use ApplicationLifetime to set a flag which indicates whether or not the code is running in the previewer… 

public override void Initialize()
{
    if (ApplicationLifetime is null)
    {
        App.IsDesignTime = true;
        Console.WriteLine("App.IsDesignTime = true");
    }
    else
    {
        App.IsDesignTime = false;
        Console.WriteLine("App.IsDesignTime = false");
    }
    AvaloniaXamlLoader.Load(this);
    Console.WriteLine(System.IO.Directory.GetCurrentDirectory());
}
 

I've added a static public bool IsDesignTime to my App class - then I can determine whether or not other code in the application should be executed… 

There may be better solutions…

 

0

Hello Martin A Bradford,

Thank you for the update. The plugin does execute a part of the program to generate a preview, but Avalonia has tooling to help with separating design-time and runtime.

 

You can use Design.IsDesignMode to determine if the application is running in a designer/preview e.g.

if (Design.IsDesignMode)
{
     Console.WriteLine("IsDesignMode = true");
}
else
{
    Console.WriteLine("IsDesignMode = false");
}

0

Thank you - that is cleaner!

It would be good it this could be more clearly documented - I just searched the Avalonia documentation and found no mention of it. In my case, it was just a puzzling annoyance, but I could imagine contexts where the unexpected execution of code could cause operational issues for a system with potential financial impact.

Martin

0

Hello Martin A Bradford,

Just want to let you know that I published a short article about this case SUPPORT-A-1181 Why is Rider executing Avalonia application code after building it?

This article includes links to relevant Avalonia documentation that describes design-time properties and data in more detail.

 

0

Please sign in to leave a comment.