【问题标题】:The .cs files are not under the .xaml file.cs 文件不在 .xaml 文件下
【发布时间】:2020-10-14 22:21:48
【问题描述】:
我是新手自学Xamarin,一直在做小项目,直到遇到这个问题。每次我开始新项目时,都会出现错误:
"Could not restore Packages".
App.xaml.cs 曾经在 App.xaml 之下,main.xaml.cs 曾经在 main.xaml 之下。现在他们有 2 个独立的文件。
- 1) 如何恢复包?
- 2) 如何将 .cs 文件关联到 .xaml 文件?
Here is an Image of my problem
提前致谢
【问题讨论】:
标签:
xaml
xamarin
xamarin.forms
xamarin.android
xamarin.ios
【解决方案1】:
我正在处理的一个项目有一段时间出现此问题,这就是解决问题的方法。
将此 XML 分组放在 Test.csproj 文件中。
<ItemGroup>
<!-- https://bugzilla.xamarin.com/show_bug.cgi?id=55591 -->
<None Remove="**\*.xaml" />
<Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
<EmbeddedResource Include="**\*.xaml" SubType="Designer" Generator="MSBuild:UpdateDesignTimeXaml" />
</ItemGroup>
请注意,在未来的更新中,请原谅我,因为我没有 100% 记得,Visual Studio 或 .NetStandard 的更新解决了这个问题。我们的项目不再需要这个修复。
【解决方案2】:
编辑位于 Xamarin 项目的 .xaml 文件的同一目录中的“.projitems”文件,以这种方式存在 .cs 文件和 .xaml 文件之间的关联
<Compile Include="$(MSBuildThisFileDirectory)MyPage.xaml.cs">
<DependentUpon>MyPage.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)MyPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
<Compile Update="C:\Projects\MyPage.xaml.cs">
<DependentUpon>MyPage.xaml</DependentUpon>
</Compile>
【解决方案3】:
我刚刚注意到我以前的一些解决方案文件和一个项目的 csproj 文件中的问题,我有一个视图无法正确显示。
它只为没有正确嵌套的视图提供此代码。
<ItemGroup>
<Compile Update="Views\NotProperNesting.xaml.cs">
<DependentUpon>NotProperNesting.xaml</DependentUpon>
</Compile>
</ItemGroup>
我不知道为什么它在第一个位置,但只是删除它并且它起作用了。