Open dgxhubbard opened 4 years ago
Also I removed StartupUri from App.xaml.
Could you format the code?
Do you forget add this code in your csproj file?
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
And the sdk will auto add this code.
I did not add that. Shouldn't that code be added by vs when the project is created?
@dgxhubbard The props in WindowsDesktop
picks up App.xaml
or Application.xaml
as the default ApplicationDefinition
when it exists in the project directory.
If you're changing that, you'll need to specify your own ApplicationDefinition
as @lindexi said. Generally, if you can't build with dotnet build
you're not going to be able to build with Visual Studio.
As far as changing the entry point updating the ApplicationDefinition
that's a fair point. That's a Visual Studio question, better suited for @chabiss.
Is this maybe related to this http://connect.microsoft.com/VisualStudio/feedback/details/363934/app-initializecomponent-is-not-generated-when-startupuri-and-startup-are-missing ? I couldn't find the page but the url text says basically all.
我还从App.xaml中删除了StartupUri。
I have the same problem, if I remove the StartupUri
from App.xaml
then the code generated by app.g.i.cs is missing the correct InitializeComponent
method. But I haven't had this problem before, strange bugs.
Correct app.g.i.cs/InitializeComponent template:
private bool _contentLoaded;
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "7.0.10.0")]
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/MyApp;V1.0.0.0;component/app.xaml", System.UriKind.Relative);
#line 1 "..\..\..\App.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}
This sounds like the old connect bug, which was marked as "won't fix".
I am running VS 2019 16.4.1 on net core 3.1. I select create new project "WPF App (Net Core" and the project is generated. Then I want my own startup object, I select create new class "EntryPoint" and place the code below in it. Then I select project entry point "EntryPoint" and compile. I get the error:
'App' does not contain a definition for 'InitializeComponent' and no accessible extension method 'InitializeComponent' accepting a first argument of type 'App' could be found (are you missing a using directive or an assembly reference?)
I looked at App.g.cs and even though I replaced the startup object with mine I still see a main being generated. How do I get InitializeComponent to be generated?
App.g.cs
/// <summary> /// Application Entry Point. /// </summary> [System.STAThreadAttribute()] [System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.8.1.0")] public static void Main() { Gt.ServerConnect.App app = new Gt.ServerConnect.App(); app.Run(); }
EntryPoint
`using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows;
namespace Gt.ServerConnect { public class EntryPoint { public static string Name { get { return "Gt.Lite"; } }
} `