Bug 59066 - Adding Forms item template to netstandard project does not nest xaml and xaml.cs files (DependsOn)
Summary: Adding Forms item template to netstandard project does not nest xaml and xaml...
Status: RESOLVED UPSTREAM
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Templates ()
Version: 4.7.0 (15.4)
Hardware: PC Windows
: --- major
Target Milestone: 15.5
Assignee: Joaquin Jares
URL:
Depends on:
Blocks:
 
Reported: 2017-08-26 21:50 UTC by Pierce Boggan [MSFT]
Modified: 2017-09-27 19:41 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED UPSTREAM

Description Pierce Boggan [MSFT] 2017-08-26 21:50:27 UTC
# Steps to Reproduce
1. Open a Forms app.
2. Add a .NET Standard project to the solution. Add the latest Xamarin.Forms prerelease NuGet.
3. Add a Forms item template (such as `ContentPage`) via Add -> Add File -> Xamarin.Forms -> Content Page.

# Expected Behavior
Forms xaml.cs file is "nested" under Forms .xaml file (what happens when you use `DependsOn`).

# Actual Behavior
Newly-added Forms item templates do not nest:
https://www.screencast.com/t/bRkWn7C844aO

Snippet from netstandard csproj:
  <ItemGroup>
    <Compile Update="Page1.xaml.cs">
      <SubType>Code</SubType>
    </Compile>
  </ItemGroup>

Possibly related issues: https://bugzilla.xamarin.com/show_bug.cgi?id=55901

Environment Info: https://gist.github.com/pierceboggan/b23cdc393fb5c2fc9361321bfd90cac3
Comment 1 Dakota Whipple 2017-08-30 11:21:14 UTC
I am also experiencing this issue, but it acts a bit differently. 

I'm using Visual Studio for Mac 7.2, Mono 5.4, .Net Standard 2.0, and Xamarin.Forms 2.4.0.269-pre2.

I create a new project for .Net Standard 2.0, add new file, and select Forms ContentPage Xaml. Sometimes this works correctly and I'll have an xaml file and xaml.cs file. When this happens, the InitializeCompenent will have a red squigly under it. The project will build fine but InitializeCompenent will either say "Use expression body for component" (and have me switch back and forth between => and {}) or it'll say InitializeComponent does not exist in current context. My .csproj looks like this

<ItemGroup>
  <EmbeddedResource Include="HomePage.xaml">
    <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
  </EmbeddedResource>
</ItemGroup>
<ItemGroup>
  <Compile Update="MyPage.xaml.cs">
    <DependentUpon>MyPage.xaml</DependentUpon>
  </Compile>
</ItemGroup>

Sometimes it won't give any errors but, either way, when I re-open the solution; I'll have 2 .xaml files and 1 .xaml.cs file. The .xaml file with the EmbeddedResource build action will have the .xaml.cs file nested under it while the other one has the build action set to None. At this point my .xaml.cs file no longer gives any errors and the project compiles correctly. 

If I delete the .xaml file with build action set to None I get "Could not find file 'path/to/file'". If I remove it from project it but keep on disk it'll show up when I reopen the project.

This solution that I found next I don't remember how I did but at this point I'll go under my .csproj file and add a new item group with:
<None Remove="Page.xaml"/>
At this point everything will function like it's suppose to.

HOWEVER, I found out that if I move the Page.xaml and .xaml.cs files to a new 'Pages' directory, I'll have 2 Page.xaml files and the .xaml.cs file will not be nested under either of them. I then have to manually add "Pages\Page.xaml" to the None Remove tag and Compile tag Update praperty but keep DependentUpon without the Pages folder (Page.xaml). Then it'll work normally again.

I did not actually run the project at any point. I'll update this issue if I see anything else.
Comment 2 Matt Ward 2017-08-30 19:10:40 UTC
@Dakota - Would you be able open a separate bug against VS Mac for the problem you are seeing?

https://bugzilla.xamarin.com/enter_bug.cgi?product=Xamarin%20Studio

Also can you provide more detailed repro steps (e.g. did you install Xamarin.Forms NuGet package before adding the files)? Thanks.
Comment 3 Dakota Whipple 2017-08-30 21:24:01 UTC
@Matt - Yes I can but I can't produce any more detailed reproduction steps than what I said. You actually can't add a ContentPage Xaml without Xamarin.Forms so yes, it was installed. Version# in comment
Comment 7 Pierce Boggan [MSFT] 2017-09-27 14:35:19 UTC
This is a known issue with the Visual Studio project system:
https://github.com/dotnet/project-system/issues/1467

Hence, marking this as RESOLVED -> UPSTREAM. I will update this issue when the GitHub issue linked above is resolved.
Comment 8 Mikayla Hutchinson [MSFT] 2017-09-27 19:41:55 UTC
This has been fixed in the Forms targets by adding a wildcard include that does the nesting.