Triple A
Triple A

Reputation: 15

The .cs files are not under the .xaml file

I am Newbie self learning Xamarin, I was making small projects Until I encountered this problem. every time I start new project, I get an Error:

"Could not restore Packages".

App.xaml.cs used to be under App.xaml and main.xaml.cs used to be under main.xaml. Now they 2 independent files.

Here is an Image of my problem

Thanks in advance

Upvotes: 0

Views: 1493

Answers (3)

UchiTesting
UchiTesting

Reputation: 159

I just noticed the issue on some of my former solution file and in the csproj file for one project I had one view not displaying properly. It had this code only for the view that had not proper nesting.

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

I don't know why it was there in the 1st place, but just removed it and it worked.

Upvotes: 1

Led Machine
Led Machine

Reputation: 7552

Edit your ".projitems" file located on the same directory of your .xaml files of your Xamarin project, there is the asociation between the .cs files and .xaml files in this way

<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>

Upvotes: 0

TaylorD
TaylorD

Reputation: 687

A project I am working on had the issue for awhile and this was the fix for it.

Place this XML grouping inside of your Test.csproj file.

<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>

Please note that in a future update, and forgive me because I don't 100% remember, an update of Visual Studio or .NetStandard fixed the issue. Our project no longer needs this fix.

Upvotes: 2

Related Questions