-
Notifications
You must be signed in to change notification settings - Fork 564
[One .NET] dotnet new project and item templates
#5348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,9 +108,22 @@ public override bool Execute () | |
| packWriter.WriteStartElement ("Directory"); | ||
| packWriter.WriteAttributeString ("Id", "packs"); | ||
| packWriter.WriteAttributeString ("Name", "packs"); | ||
| packWriter.WriteAttributeString ("FileSource", packs_dir); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to include a "snippet" of what the new XML output looks like with these changes?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line adds the full path such as: It was not explicitly needed before because The second block looks like: MSI has weird rules around the |
||
| foreach (var directory in Directory.EnumerateDirectories (packs_dir, "Microsoft.Android.*")) { | ||
| RecurseDirectory (packs_dir, packWriter, componentWriter, directory); | ||
| } | ||
| packWriter.WriteEndElement (); // </Directory> packs | ||
|
|
||
| // template-packs | ||
| var templates_dir = Path.Combine (DotNetPath, "template-packs"); | ||
| packWriter.WriteStartElement ("Directory"); | ||
| packWriter.WriteAttributeString ("Id", "templatepacks"); | ||
| packWriter.WriteAttributeString ("Name", "template-packs"); | ||
| packWriter.WriteAttributeString ("FileSource", templates_dir); | ||
| foreach (var file in Directory.EnumerateFiles (templates_dir, "Microsoft.Android.Templates.*.nupkg")) { | ||
| AddFile (templates_dir, packWriter, componentWriter, file); | ||
| } | ||
| packWriter.WriteEndElement (); // </Directory> template-packs | ||
|
|
||
| packWriter.WriteEndDocument (); // </Directory> | ||
| componentWriter.WriteEndDocument (); // </ComponentGroup> | ||
|
|
@@ -145,22 +158,27 @@ static void RecurseDirectory (string top_dir, XmlWriter packWriter, XmlWriter co | |
| var fileName = Path.GetFileName (file); | ||
| if (fileName.StartsWith (".") || fileName.StartsWith ("_")) | ||
| continue; | ||
| var componentId = GetId (top_dir, file); | ||
| packWriter.WriteStartElement ("Component"); | ||
| packWriter.WriteAttributeString ("Id", componentId); | ||
| packWriter.WriteStartElement ("File"); | ||
| packWriter.WriteAttributeString ("Id", componentId); | ||
| packWriter.WriteAttributeString ("Name", Path.GetFileName (file)); | ||
| packWriter.WriteAttributeString ("KeyPath", "yes"); | ||
| packWriter.WriteEndElement (); // </File> | ||
| packWriter.WriteEndElement (); // </Component> | ||
| componentWriter.WriteStartElement ("ComponentRef"); | ||
| componentWriter.WriteAttributeString ("Id", componentId); | ||
| componentWriter.WriteEndElement (); // </ComponentRef> | ||
| AddFile (top_dir, packWriter, componentWriter, file); | ||
| } | ||
| packWriter.WriteEndElement (); // </Directory> | ||
| } | ||
|
|
||
| static void AddFile (string top_dir, XmlWriter packWriter, XmlWriter componentWriter, string file) | ||
| { | ||
| string componentId = GetId (top_dir, file); | ||
| packWriter.WriteStartElement ("Component"); | ||
| packWriter.WriteAttributeString ("Id", componentId); | ||
| packWriter.WriteStartElement ("File"); | ||
| packWriter.WriteAttributeString ("Id", componentId); | ||
| packWriter.WriteAttributeString ("Name", Path.GetFileName (file)); | ||
| packWriter.WriteAttributeString ("KeyPath", "yes"); | ||
| packWriter.WriteEndElement (); // </File> | ||
| packWriter.WriteEndElement (); // </Component> | ||
| componentWriter.WriteStartElement ("ComponentRef"); | ||
| componentWriter.WriteAttributeString ("Id", componentId); | ||
| componentWriter.WriteEndElement (); // </ComponentRef> | ||
| } | ||
|
|
||
| static string GetId (string top_dir, string path) | ||
| { | ||
| if (string.IsNullOrEmpty (path)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project> | ||
| <Import Project="..\..\build-tools\scripts\XAVersionInfo.targets" /> | ||
| <PropertyGroup> | ||
| <BeforePack> | ||
| _GetDefaultPackageVersion; | ||
| $(BeforePack); | ||
| </BeforePack> | ||
| </PropertyGroup> | ||
| <Target Name="_GetDefaultPackageVersion" | ||
| DependsOnTargets="GetXAVersionInfo" > | ||
| <PropertyGroup> | ||
| <PackageVersion>$(AndroidPackVersionLong)+sha.$(XAVersionHash)</PackageVersion> | ||
| </PropertyGroup> | ||
| </Target> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <PackageType>Template</PackageType> | ||
| <PackageId>Microsoft.Android.Templates</PackageId> | ||
| <Title>.NET Android Templates</Title> | ||
| <Authors>Microsoft</Authors> | ||
| <Description>Templates for Android platforms.</Description> | ||
| <IncludeContentInPack>true</IncludeContentInPack> | ||
| <IncludeBuildOutput>false</IncludeBuildOutput> | ||
| <ContentTargetFolders>content</ContentTargetFolders> | ||
| <OutputPath>..\..\bin\Build$(Configuration)\nupkgs\</OutputPath> | ||
| </PropertyGroup> | ||
|
|
||
| <Import Project="..\..\Configuration.props" /> | ||
|
|
||
| <ItemGroup> | ||
| <Content Include="**\*" Exclude="**\bin\**;**\obj\**" /> | ||
| <Compile Remove="**\*" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/template", | ||
| "author": "Microsoft", | ||
| "classifications": [ "Android" ], | ||
| "name": "Android Activity template", | ||
| "description": "An Android Activity class", | ||
| "tags": { | ||
| "language": "C#", | ||
| "type": "item" | ||
| }, | ||
| "identity": "Microsoft.Android.AndroidActivity", | ||
| "shortName": "android-activity", | ||
| "sourceName": "Activity1", | ||
| "primaryOutputs": [ | ||
| { "path": "Activity1.cs" } | ||
| ], | ||
| "defaultName": "Activity1", | ||
| "symbols": { | ||
| "namespace": { | ||
| "description": "namespace for the generated code", | ||
| "replaces": "AndroidApp1", | ||
| "type": "parameter" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| using Android.App; | ||
| using Android.OS; | ||
| using Android.Runtime; | ||
| using Android.Widget; | ||
|
|
||
| namespace AndroidApp1 | ||
| { | ||
| [Activity(Label = "@string/app_name", MainLauncher = true)] | ||
| public class Activity1 : Activity | ||
| { | ||
| protected override void OnCreate(Bundle savedInstanceState) | ||
| { | ||
| base.OnCreate(savedInstanceState); | ||
|
|
||
| // Create your application here | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/template", | ||
| "author": "Microsoft", | ||
| "classifications": [ "Android" ], | ||
| "identity": "Microsoft.Android.AndroidBinding", | ||
| "name": "Android Java Library Binding", | ||
| "description": "A project for creating an Android class library that binds to a native Java library", | ||
| "shortName": "android-bindinglib", | ||
| "tags": { | ||
| "language": "C#", | ||
| "type": "project" | ||
| }, | ||
| "sourceName": "AndroidBinding1", | ||
| "preferNameDirectory": true, | ||
| "primaryOutputs": [ | ||
| { "path": "AndroidBinding1.csproj" } | ||
| ], | ||
| "defaultName": "AndroidBinding1" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| Additions allow you to add arbitrary C# to the generated classes | ||
| before they are compiled. This can be helpful for providing convenience | ||
| methods or adding pure C# classes. | ||
|
|
||
| == Adding Methods to Generated Classes == | ||
|
|
||
| Let's say the library being bound has a Rectangle class with a constructor | ||
| that takes an x and y position, and a width and length size. It will look like | ||
| this: | ||
|
|
||
| public partial class Rectangle | ||
| { | ||
| public Rectangle (int x, int y, int width, int height) | ||
| { | ||
| // JNI bindings | ||
| } | ||
| } | ||
|
|
||
| Imagine we want to add a constructor to this class that takes a Point and | ||
| Size structure instead of 4 ints. We can add a new file called Rectangle.cs | ||
| with a partial class containing our new method: | ||
|
|
||
| public partial class Rectangle | ||
| { | ||
| public Rectangle (Point location, Size size) : | ||
| this (location.X, location.Y, size.Width, size.Height) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| At compile time, the additions class will be added to the generated class | ||
| and the final assembly will a Rectangle class with both constructors. | ||
|
|
||
|
|
||
| == Adding C# Classes == | ||
|
|
||
| Another thing that can be done is adding fully C# managed classes to the | ||
| generated library. In the above example, let's assume that there isn't a | ||
| Point class available in Java or our library. The one we create doesn't need | ||
| to interact with Java, so we'll create it like a normal class in C#. | ||
|
|
||
| By adding a Point.cs file with this class, it will end up in the binding library: | ||
|
|
||
| public class Point | ||
| { | ||
| public int X { get; set; } | ||
| public int Y { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net6.0-android</TargetFramework> | ||
| <RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">AndroidBinding1</RootNamespace> | ||
| </PropertyGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <enum-field-mappings> | ||
| <!-- | ||
| This example converts the constants Fragment_id, Fragment_name, | ||
| and Fragment_tag from android.support.v4.app.FragmentActivity.FragmentTag | ||
| to an enum called Android.Support.V4.App.FragmentTagType with values | ||
| Id, Name, and Tag. | ||
| <mapping jni-class="android/support/v4/app/FragmentActivity$FragmentTag" clr-enum-type="Android.Support.V4.App.FragmentTagType"> | ||
| <field jni-name="Fragment_name" clr-name="Name" value="0" /> | ||
| <field jni-name="Fragment_id" clr-name="Id" value="1" /> | ||
| <field jni-name="Fragment_tag" clr-name="Tag" value="2" /> | ||
| </mapping> | ||
| --> | ||
| </enum-field-mappings> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <enum-method-mappings> | ||
| <!-- | ||
| This example changes the Java method: | ||
| android.support.v4.app.Fragment.SavedState.writeToParcel (int flags) | ||
| to be: | ||
| android.support.v4.app.Fragment.SavedState.writeToParcel (Android.OS.ParcelableWriteFlags flags) | ||
| when bound in C#. | ||
| <mapping jni-class="android/support/v4/app/Fragment.SavedState"> | ||
| <method jni-name="writeToParcel" parameter="flags" clr-enum-type="Android.OS.ParcelableWriteFlags" /> | ||
| </mapping> | ||
| --> | ||
| </enum-method-mappings> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <metadata> | ||
| <!-- | ||
| This sample removes the class: android.support.v4.content.AsyncTaskLoader.LoadTask: | ||
| <remove-node path="/api/package[@name='android.support.v4.content']/class[@name='AsyncTaskLoader.LoadTask']" /> | ||
|
|
||
| This sample removes the method: android.support.v4.content.CursorLoader.loadInBackground: | ||
| <remove-node path="/api/package[@name='android.support.v4.content']/class[@name='CursorLoader']/method[@name='loadInBackground']" /> | ||
| --> | ||
| </metadata> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May want to omit the entries that don't appear to follow convention, so skip
consoleandclasslib& the rest, but includewpfandwpflib.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I included
wpf,wpflib,nunit, andnunit-test. I don't think we should dropconsoleorclasslibfrom this example, because those are the most basic templates.