-
Notifications
You must be signed in to change notification settings - Fork 33
Documentation for Extending NuGet Packages #90
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e2d7d3
Modified the verisons in the Readme
21aadef
Added documentation for augmenting NuGet packages to support MSBuildF…
f3b2365
Merge
6d79117
Update Documentation/CraftingNuGetPackages.md
e734584
Updated based on feedback:
079ed35
Updated not at the top to stand out more
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Crafting a NuGet Package for MSB4U | ||
|
|
||
| MSBuildForUnity (MSB4U) consumes .NET based packages **without any modifications** to the package. This documentation describes how C++, WinRT or packages with Unity-specific contents can easily be adapted to work with MSBuildForUnity. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| A NuGet package is enabled for MSB4U through the use of a [Build Targets or Props](https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#include-msbuild-props-and-targets-in-a-package) file inside a NuGet package, and a set of properties provided by MSB4U. The props/targets file is then responsible for declaring the contents that will get placed into the package consumer's Unity project. Essentially, the steps are as follows: | ||
|
|
||
| 1. In your package root, add a `Unity` folder with content to be placed into the consumer's Unity project: | ||
| - Assets - prefabs, meshes, textures, etc | ||
| - Native DLLs for each platform you support. | ||
| - Unity .meta files for the Assets and DLLs (with appropriate architecture marked) | ||
| 2. Add a `build/<YourNuGetPackageName>.targets` file to your package, with the following contents: | ||
|
|
||
| ```xml | ||
| <Project> | ||
| <PropertyGroup> | ||
| <!--All extra resources for this package will be placed under this folder in the output directory.--> | ||
| <PackageDestinationFolder>$(MSBuildThisFileName)</PackageDestinationFolder> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup Condition="'$(MSBuildForUnityVersion)' != ''"> | ||
| <Content Include="$(MSBuildThisFileDirectory)..\Unity\**"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <!-- Don't show .meta files in Solution Explorer - it's not useful. --> | ||
| <Visible Condition="'%(Extension)' == '.meta'">false</Visible> | ||
| <Link>$(PackageDestinationFolder)\%(RecursiveDir)%(Filename)%(Extension)</Link> | ||
| </Content> | ||
| </ItemGroup> | ||
| </Project> | ||
| ``` | ||
|
|
||
| > This is a real example taken from the [Microsoft.Windows.MixedReality.DotNetWinRT](https://www.nuget.org/packages/Microsoft.Windows.MixedReality.DotNetWinRT/) NuGet package. | ||
|
|
||
| ### What Happens | ||
|
|
||
| Those two steps are the basics for getting up to speed. When MSB4U is used to reference your NuGet package, the following will happen: | ||
|
|
||
| - Using the active Target Framework (.NET46, .NET Standard 2.0) configured in the consumer's Unity project, MSBuild will pick up the DLL from the libs folder and bring it into the Unity project. | ||
| - Furthermore, MSBuild will automatically reference the `.targets` file. | ||
| - MSB4U has a property `MSBuildForUnityVersion` declared, and thereby the condition `'$(MSBuildForUnityVersion)' != ''` will evaluate to `true`. | ||
| - This will include the Unity folder in your NuGet package as Content, which will get put into the consumer's Unity project. | ||
|
|
||
| ### Properties Provided Through MSBuildForUnity | ||
|
|
||
| The following properties are either passed through as the build CLI argument, or available in the Unity Project root's `MSBuildForUnity.Common.props` file. | ||
|
|
||
| - **UnityConfiguration:** Whether we are building for `InEditor` or `Player`. (**LIMITATION** we only support `InEditor` for now; [Issue #59](https://github.com/microsoft/MSBuildForUnity/issues/59)) | ||
| - **UnityPlatform:** The platform that we are building for, the values match Unity's `BuildTarget` enum ([documentation](https://docs.unity3d.com/ScriptReference/BuildTarget.html)) | ||
| - **MSBuildForUnityVersion:** The `{Major}.{Minor}.{Patch}` version of MSBuildForUnity, it can be used in comparison. | ||
| - **MSBuildForUnityDefaultOutputPath:** The default output path for the Unity project's dependencies. | ||
| > **NOTE:** Don't rely on this unless you absolutely need to, rely on default MSBuild "copy-to-output" behavior. | ||
| - `(MSBuild)` **TargetFramework:** By default, MSBuild will make TargetFramework available. | ||
| > MSBuild will also automatically bring in the DLLs from the NuGet packages' matching target framework folder. | ||
| - **UnityMajorVersion:** The major version of Unity (ie. 2018, 2019, etc) | ||
| - **UnityMinorVersion:** The minor version of Unity (ie. 1, 2, 3, 4) | ||
|
|
||
| ### Limitations | ||
|
|
||
| Because all package resolution happens in the Unity Editor during edit-time compilation, we don't have access to the target architecture of the final device the code will live on. Because of this, we must include all flavors of Native binaries. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.