.cs文件不在.xaml文件下

.cs文件不在.xaml文件下,xaml,xamarin,xamarin.forms,xamarin.android,xamarin.ios,Xaml,Xamarin,Xamarin.forms,Xamarin.android,Xamarin.ios,我是新手,自学Xamarin,在遇到这个问题之前,我一直在做一些小项目。每次启动新项目时,我都会遇到一个错误: “无法还原包”。 App.xaml.cs过去位于App.xaml下,main.xaml.cs过去位于main.xaml下。现在他们有两个独立的文件 1) 如何恢复软件包 2) 如何将.cs文件与.xaml文件关联 提前感谢我正在处理的一个项目有一段时间出现了这个问题,这就是它的修复方法 将此XML分组放入Test.csproj文件中 <ItemGroup> &

我是新手,自学Xamarin,在遇到这个问题之前,我一直在做一些小项目。每次启动新项目时,我都会遇到一个错误:

“无法还原包”。

App.xaml.cs
过去位于
App.xaml
下,
main.xaml.cs
过去位于
main.xaml
下。现在他们有两个独立的文件

  • 1) 如何恢复软件包
  • 2) 如何将.cs文件与.xaml文件关联


提前感谢

我正在处理的一个项目有一段时间出现了这个问题,这就是它的修复方法

将此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的更新修复了此问题。我们的项目不再需要此修复。

我正在处理的一个项目有一段时间存在此问题,而这就是它的修复

将此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的更新修复了此问题。我们的项目不再需要此修复。

编辑您的.projitems”文件,该文件位于Xamarin项目的.xaml文件的同一目录中,在.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>

MyPage.xaml
代码
设计师
MSBuild:编译
MyPage.xaml
编辑您的.projitems文件,该文件位于Xamarin项目的.xaml文件的同一目录中。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>

MyPage.xaml
代码
设计师
MSBuild:编译
MyPage.xaml

我刚刚注意到我以前的一些解决方案文件中的问题,在一个项目的csproj文件中,有一个视图没有正确显示。 该代码仅用于没有正确嵌套的视图

<ItemGroup>
  <Compile Update="Views\NotProperNesting.xaml.cs">
    <DependentUpon>NotProperNesting.xaml</DependentUpon>
  </Compile>
</ItemGroup>

NotProperNesting.xaml

我不知道为什么它会出现在第一位,但只是删除了它,它就工作了。

我只是注意到我以前的一些解决方案文件和一个项目的csproj文件中有一个视图没有正确显示。 该代码仅用于没有正确嵌套的视图

<ItemGroup>
  <Compile Update="Views\NotProperNesting.xaml.cs">
    <DependentUpon>NotProperNesting.xaml</DependentUpon>
  </Compile>
</ItemGroup>

NotProperNesting.xaml

我不知道为什么它放在第一位,但只要把它取下来就行了。

谢谢,这就解决了我的问题。现在,文件被嵌套为假定为beThanks,这解决了我的问题。现在,该文件按照假定的方式嵌套