Skip to content

Commit

Permalink
New experiment improvements (#131)
Browse files Browse the repository at this point in the history
* Test projects to reference the project with the experiment code

Duplicated change with #126

* Update the displayed template name

* Increase the namespaces referenced in the example test file

This list is based on what's most commonly used in existing toolkit tests.

* Make internal classes visible to all test projects

For #127

* set type to "solution"

as per dotnet/templating#4771

* Add more info about a created solution for a new experiment

For #127

* Don't include the labexp template in VS

it doesn't work there

* Update template/README.md

Co-authored-by: Arlo <[email protected]>

* Update template/README.md

Co-authored-by: Arlo <[email protected]>

* Update template/README.md

Co-authored-by: Michael Hawker MSFT (XAML Llama) <[email protected]>

* Update template/README.md

Co-authored-by: Michael Hawker MSFT (XAML Llama) <[email protected]>

* Update template/README.md

Co-authored-by: Michael Hawker MSFT (XAML Llama) <[email protected]>

* Update template/README.md

Co-authored-by: Michael Hawker MSFT (XAML Llama) <[email protected]>

* Revert "Test projects to reference the project with the experiment code"

This reverts commit 5dccf8a.

* Update example test

to reference the code being developed
& to use a naming convention better matched to the wider toolkit convention

* increase the number of namespaces included by default in the generated code

This is to reduce the effort required to begin work on an experiment.

* add placeholders and TODO notes for including links to relevant discussion & issue

* update new experiment doc to reflect changes in solution structure

Co-authored-by: Arlo <[email protected]>
Co-authored-by: Michael Hawker MSFT (XAML Llama) <[email protected]>
  • Loading branch information
3 people authored Jun 7, 2022
1 parent aba0670 commit e6389b0
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 5 deletions.
35 changes: 34 additions & 1 deletion template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,37 @@ dotnet new labexp -n MyExperimentNameHere
```

This creates a new experiment called "MyExperimentNameHere".
You can now open `./labs/MyExperimentNameHere/MyExperimentNameHere.sln` and create something amazing!
You can now open `./labs/MyExperimentNameHere/MyExperimentNameHere.sln` and start your experiment.

### Inside the generated solution

The solution includes many projects but is not as complicated as you might first think.

#### Things you can ignore

The `Labs Dependencies` folder can be ignored. The projects it contains are referenced in other projects and you should not change anything here.

The `Platforms` folder contains projects that host your sample(s) on different platforms. Run any of these projects to see your sample running inside a UWP, WASM, or WinAppSdk/WinUI3 app. Again, you shouldn't modify anything in these projects.

The `Tests` folder contains projects used to run the tests on different platforms. Details of where to create tests for the code in the experiment are below.

#### Where to add your code

The main code of your experiment will go in the project `CommunityToolkit.Labs.WinUI.MyExperimentNameHere`. When an experiment is merged into Labs, this code will be bundled automatically in a NuGet package and pushed to the Labs DevOps feed. This will let others try out your experiment and provide feedback to further your experiment.
You will find an empty class in `MyExperimentNameHere.cs` that you can use as your starting point.

The project `MyExperimentNameHere.Sample`is where you can put code that will allow you to demonstrate and exercise the experiment. In this project you'll find a sample page that includes an example of how to use settings and properties that can be controlled within the sample app. This folder also contains a markdown file that contains the documentation for the experiment and how to use it.

Tests for the code in the experiment go in the `MyExperimentNameHere.Tests` project. This is a shared project that is referenced by the other test projects. This makes it easy to check that the experiment's code works in more than one place. There's an example test inside the `ExampleMyExperimentNameHereTestClass.cs` file

### If things go wrong

Hopefully, you'll have no problems creating your experiment. However, here are details of how to address some of the things that might go wrong.

#### Missing components or workloads

Visual Studio will prompt if any required components or workloads are missing. Make sure all these are installed before continuing.

#### Creating an experiment in the wrong place

The generated solution and some of the projects it contains rely on relative paths that assume the experiment is created in the `labs` directory. If the experiment is created elsewhere, the error message "One or more projects in the solution were not loaded correctly." will be shown when opening the solution. Deleting the incorrect solution and recreating in the correct location is the most reliable way to address this.
7 changes: 7 additions & 0 deletions template/lab/.template.config/ide.host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"unsupportedHosts": [
{
"id": "vs"
}
]
}
4 changes: 2 additions & 2 deletions template/lab/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"Toolkit",
"Labs"
],
"name": "Community Toolkit Labs Project Template",
"name": "Community Toolkit Labs Experiment",
"identity": "CommunityToolkit.Labs.ProjectTemplate",
"shortName": "labexp",
"tags": {
"language": "C#",
"type": "project"
"type": "solution"
},
"sourceName": "ProjectTemplate",
"preferNameDirectory": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ subcategory: Layout

# ProjectTemplate

For more information about this experiment see:
- Discussion: TODO: PASTE LINK HERE
- Issue: TODO: PASTE LINK HERE

TODO: Fill in information about this experiment and how to get started here...

> [!SAMPLE ProjectTemplateFirstSamplePage]
13 changes: 13 additions & 0 deletions template/lab/src/AdditionalAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;

// These `InternalsVisibleTo` calls are intended to make it easier for
// for any internal code to be testable in all the different test projects
// used with the Labs infrastructure.
[assembly: InternalsVisibleTo("ProjectTemplate.UnitTests.Uwp")]
[assembly: InternalsVisibleTo("ProjectTemplate.UnitTests.WinAppSdk")]
[assembly: InternalsVisibleTo("CommunityToolkit.Labs.UnitTests.Uwp")]
[assembly: InternalsVisibleTo("CommunityToolkit.Labs.UnitTests.WinAppSdk")]
10 changes: 10 additions & 0 deletions template/lab/src/ProjectTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
using System.Collections.Generic;
using Windows.Foundation;

// TODO: remove any unneeded namespaces before creating a PR
//-:cnd:noEmit
#if !WINAPPSDK
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
#else
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Markup;
using Microsoft.UI.Xaml.Media;
#endif
//+:cnd:noEmit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,37 @@
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CommunityToolkit.Labs.WinUI;

//-:cnd:noEmit
#if !WINAPPSDK
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
#else
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Markup;
using Microsoft.UI.Xaml.Media;
#endif
//+:cnd:noEmit

namespace ProjectTemplate.Tests
{
[TestClass]
public class ExampleProjectTemplateTestClass
{
[TestMethod]
public void Just_an_example_test()
public void SimpleExampleTest()
{
Assert.AreEqual(1, 1);
var systemUnderTest = new CommunityToolkit.Labs.WinUI.ProjectTemplate();
Assert.IsNotNull(systemUnderTest);
}
}
}

0 comments on commit e6389b0

Please sign in to comment.