Search code examples
xamlxamarinxamarin.formsxamarin.androidxamarin.ios

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.

  • 1) How can I restore packages?
  • 2) How can I associate .cs file to .xaml file?

Here is an Image of my problem

Thanks in advance


Solution

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