Skip to content
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

Add sample for External dependencies and update Project Generator #35

Merged
merged 20 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# MSBuildForUnity

MSBuildForUnity is a [collection of tools](#features) to help integrate MSBuild with Unity. This is helpful in leveraging more of the .NET ecosystem within Unity. Some things this project helps with are:
- Sharing code (via an MSBuild project) between Unity and other .NET projects (such as UWP XAML apps, Xamarin apps, etc.).
MSBuildForUnity solves the problem of establishing clear dependency relationships between Unity project and other .NET components such as external (to Unity) C# projects, or NuGet packages. It creates a familiar to .NET developers project structure and ensures that the dependencies are resolved and brought into the Unity project as appropriate. With this component, you can:

- Share code between Unity and other .NET projects (such as UWP XAML apps, Xamarin apps, etc.).
- Consuming existing .NET components (e.g. NuGet packages).

The samples included in this repository best convey the simplicity and value of this component:

- [Simple NuGet Dependency Sample](Samples/SimpleNuGetDependency.Unity/Readme.md) - Showcases the simplest and most minimal usage of this component to pull in a dependency.
- [Integrated Dependencies Sample](Samples/IntegratedDependencies.Unity/Readme.md) - Showcases the power of this component by relying on project generation.

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Expand Down Expand Up @@ -117,4 +123,4 @@ For details, see the [documentation](Documentation/MSBuildForUnityNuGetPackage/M
[NuGetBuild]: https://dev.azure.com/UnityDeveloperTools/MSBuildForUnity/_build/latest?definitionId=3&branchName=master

[NuGetPackageBadge]: https://feeds.dev.azure.com/UnityDeveloperTools/0cb95e25-9194-4ccd-9afb-439b25ecb93a/_apis/public/Packaging/Feeds/a3d1c3cc-6042-4e05-b699-39a947e75639/Packages/bdf78d31-dd97-4f6b-befb-75bb6185172e/Badge
[NuGetPackage]: https://dev.azure.com/UnityDeveloperTools/MSBuildForUnity/_packaging?_a=package&feed=a3d1c3cc-6042-4e05-b699-39a947e75639&package=bdf78d31-dd97-4f6b-befb-75bb6185172e&preferRelease=true
[NuGetPackage]: https://dev.azure.com/UnityDeveloperTools/MSBuildForUnity/_packaging?_a=package&feed=a3d1c3cc-6042-4e05-b699-39a947e75639&package=bdf78d31-dd97-4f6b-befb-75bb6185172e&preferRelease=true
70 changes: 70 additions & 0 deletions Samples/IntegratedDependencies.Unity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Mm]emoryCaptures/

# Never ignore Asset meta data
!/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

# Custom MSBuildForUnity Project Related ignore entries
/MSBuild/*
!/MSBuild/Publish/
!/MSBuild/settings.json
/MSBuild/Publish/**/*.dll
/MSBuild/Publish/**/*.pdb
/MSBuildForUnity.Common.props
!/Assets/**/*.msb4u.*
!/Packages/**/*.msb4u.*
/Assets/Dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project ToolsVersion="15.0">
<!--GENERATED FILE-->
<!--
This file can be modified and checked in as long as the following rules are met:
- Both the imports are present:
- - <Import Project="$(MSBuildProjectName).g.props" />
- - <Import Project="$(MSBuildProjectName).g.targets" />
- Nothing above the props import or below the targets import is modified
- No C# source files are added for compilation

You can modify this file as follows:
- Add NuGet package references:
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
</ItemGroup>
- Add external C# project references:
<ItemGroup>
<ProjectReference Include="..\..\..\ExternalLib\ExternalLib.csproj" />
</ItemGroup>
-->

<Import Project="$([MSBuild]::GetPathOfFileAbove(MSBuildForUnity.Common.props))" Condition="Exists('$([MSBuild]::GetPathOfFileAbove(MSBuildForUnity.Common.props))')" />
<PropertyGroup>
<!--anborod: This is a weird thing, it is a required property (even if commented)-->
<!--<TargetFrameworks>netstandard2.0;uap10.0;net46</TargetFrameworks> -->
</PropertyGroup>

<Import Project="$(MSBuildForUnityGeneratedOutputDirectory)\$(MSBuildProjectName).g.props" />

<ItemGroup>
<!-- Add your references here -->
<ProjectReference Include="..\External\CommonLibrary\CommonLibrary.csproj" />
</ItemGroup>

<Import Project="$(MSBuildForUnityGeneratedOutputDirectory)\$(MSBuildProjectName).g.targets" />
</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Samples/IntegratedDependencies.Unity/Assets/Dependencies.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project ToolsVersion="15.0">
<!--GENERATED FILE-->
<!--
This file can be modified and checked in.

It is different from the other generated C# Projects in that it will be the one gathering all dependencies and placing them into the Unity asset folder.

You can add project level dependencies to this file, by placing them below:
- <Import Project="$(MSBuildForUnityGeneratedOutputDirectory)\$(MSBuildProjectName).g.props" />
and before:
- <Import Project="$(MSBuildForUnityGeneratedOutputDirectory)\$(MSBuildProjectName).g.targets" />

Do not add any source or compliation items.

Examples of how you can modify this file:
- Add NuGet package references:
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
</ItemGroup>
- Add external C# project references:
<ItemGroup>
<ProjectReference Include="..\..\..\ExternalLib\ExternalLib.csproj" />
</ItemGroup>
-->

<Import Project="$([MSBuild]::GetPathOfFileAbove(MSBuildForUnity.Common.props))" Condition="Exists('$([MSBuild]::GetPathOfFileAbove(MSBuildForUnity.Common.props))')" />

<PropertyGroup>
<!--anborod: This is a weird thing, it is a required property (even if commented)-->
<!--<TargetFrameworks>netstandard2.0;uap10.0;net46</TargetFrameworks> -->
</PropertyGroup>

<Import Project="$(MSBuildForUnityGeneratedOutputDirectory)\$(MSBuildProjectName).g.props" />

<ItemGroup>

</ItemGroup>

<Import Project="$(MSBuildForUnityGeneratedOutputDirectory)\$(MSBuildProjectName).g.targets" />
</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Samples/IntegratedDependencies.Unity/Assets/NonComponentType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using CommonLibrary;
using UnityEngine;

public class NonComponentType : MonoBehaviour
{
private void Start()
{
Debug.Log(new CommonComponent().GetData());
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Samples/IntegratedDependencies.Unity/Assets/NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="MSBuildForUnity" value="https://pkgs.dev.azure.com/UnityDeveloperTools/MSBuildForUnity/_packaging/UnityDeveloperTools/nuget/v3/index.json" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
32 changes: 32 additions & 0 deletions Samples/IntegratedDependencies.Unity/Assets/NuGet.config.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading