Fix Platform and TargetFramework switching (#70)
* Rework automatic generation logic, and ensure cleanning of build artifacts is done at appropriate times. * Removing debug logs. * A few minor fixes to strengthen regen for correct times. * Updated versions to 0.8.2 * Forcing NuGet packages to be copied out to bin folder
This commit is contained in:
Родитель
bf60529cbd
Коммит
d1e3a15530
|
@ -68,7 +68,7 @@ This scenario leverages the MSBuildForUnity [Project Builder](#msbuild-project-b
|
|||
```
|
||||
- Add the following to the `dependencies` section of the file:
|
||||
```json
|
||||
"com.microsoft.msbuildforunity": "0.8.1"
|
||||
"com.microsoft.msbuildforunity": "0.8.2"
|
||||
```
|
||||
1. Create a "SDK style" MSBuild project (e.g. csproj) somewhere under your `Assets` directory of your Unity project that references the `MSBuildForUnity` NuGet package. Here is an example:
|
||||
```xml
|
||||
|
@ -77,7 +77,7 @@ This scenario leverages the MSBuildForUnity [Project Builder](#msbuild-project-b
|
|||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MSBuildForUnity" Version="0.8.1">
|
||||
<PackageReference Include="MSBuildForUnity" Version="0.8.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MSBuildForUnity" Version="[0.8.1-*, 0.8.1]">
|
||||
<PackageReference Include="MSBuildForUnity" Version="[0.8.2-*, 0.8.2]">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
|
|
@ -17,10 +17,12 @@
|
|||
<BaseIntermediateOutputPath>$(MSBuildForUnityGeneratedOutputDirectory)\..\Output\obj\Dependencies</BaseIntermediateOutputPath>
|
||||
<OutputPath>Dependencies</OutputPath>
|
||||
<EnableDefaultItems>false</EnableDefaultItems>
|
||||
<!--Copy the NuGet package reference dlls as well.-->
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MSBuildForUnity" Version="[0.8.1-*, 0.8.1]">
|
||||
<PackageReference Include="MSBuildForUnity" Version="[0.8.2-*, 0.8.2]">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<MSBuildForUnityVersion>0.8.1</MSBuildForUnityVersion>
|
||||
<MSBuildForUnityVersion>0.8.2</MSBuildForUnityVersion>
|
||||
|
||||
<MSBuildForUnityGeneratedOutputDirectory><!--GENERATED_OUTPUT_DIRECTORY_TOKEN--></MSBuildForUnityGeneratedOutputDirectory>
|
||||
<UnityProjectAssetsPath><!--UNITY_PROJECT_ASSETS_PATH_TOKEN--></UnityProjectAssetsPath>
|
||||
|
@ -12,4 +12,8 @@
|
|||
<UnityMajorVersion><!--UNITY_MAJOR_VERSION_TOKEN--></UnityMajorVersion>
|
||||
<UnityMinorVersion><!--UNITY_MINOR_VERSION_TOKEN--></UnityMinorVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="_RemoveOutputDirectory" AfterTargets="Clean">
|
||||
<RemoveDir Directories="$(OutputPath)"/>
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
|
@ -62,9 +62,10 @@ namespace Microsoft.Build.Unity.ProjectGeneration
|
|||
|
||||
public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget)
|
||||
{
|
||||
MSBuildProjectBuilder.TryBuildAllProjects(MSBuildProjectBuilder.CleanProfileName);
|
||||
RunCoreAutoGenerate(true);
|
||||
MSBuildProjectBuilder.TryBuildAllProjects(MSBuildProjectBuilder.BuildProfileName);
|
||||
if (EditorAnalyticsSessionInfo.elapsedTime > 0)
|
||||
{
|
||||
RefreshGeneratedOutput(forceGenerateEverything: Config.AutoGenerateEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +108,8 @@ namespace Microsoft.Build.Unity.ProjectGeneration
|
|||
{
|
||||
Config.AutoGenerateEnabled = !Config.AutoGenerateEnabled;
|
||||
Menu.SetChecked(AutoGenerate, Config.AutoGenerateEnabled);
|
||||
RunCoreAutoGenerate(false);
|
||||
// If we just toggled on, regenerate everything
|
||||
RefreshGeneratedOutput(forceGenerateEverything: Config.AutoGenerateEnabled);
|
||||
}
|
||||
|
||||
[MenuItem(AutoGenerate, true, priority = 101)]
|
||||
|
@ -123,7 +125,7 @@ namespace Microsoft.Build.Unity.ProjectGeneration
|
|||
{
|
||||
try
|
||||
{
|
||||
RegenerateEverything(true);
|
||||
RefreshGeneratedOutput(forceGenerateEverything: true);
|
||||
Debug.Log($"{nameof(GenerateSDKProjects)} Completed Succesfully.");
|
||||
}
|
||||
catch
|
||||
|
@ -135,28 +137,77 @@ namespace Microsoft.Build.Unity.ProjectGeneration
|
|||
|
||||
static MSBuildTools()
|
||||
{
|
||||
RunCoreAutoGenerate(false);
|
||||
if (EditorAnalyticsSessionInfo.elapsedTime == 0)
|
||||
{
|
||||
// The Unity asset database cannot be queried until the Editor is fully loaded. The first editor update tick seems to be a safe bet for this.
|
||||
|
||||
// Ensure a single invocation
|
||||
EditorApplication.update -= OnUpdate;
|
||||
EditorApplication.update += OnUpdate;
|
||||
void OnUpdate()
|
||||
{
|
||||
RefreshGeneratedOutput(forceGenerateEverything: false);
|
||||
EditorApplication.update -= OnUpdate;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshGeneratedOutput(forceGenerateEverything: false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunCoreAutoGenerate(bool skipTokenFileCheck)
|
||||
private static void RefreshGeneratedOutput(bool forceGenerateEverything)
|
||||
{
|
||||
// Check if a file exists, if it does, we already generated this editor instance
|
||||
bool fileExists = File.Exists(TokenFilePath);
|
||||
if (!fileExists || skipTokenFileCheck)
|
||||
// In this method, the following must happen
|
||||
// - Clean up builds if necessary
|
||||
// - Generate the common props file if necessary
|
||||
// - Regenerate everything else if necessary
|
||||
// - Build if the clean was done
|
||||
|
||||
BuildTarget currentBuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
ApiCompatibilityLevel targetFramework = PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
|
||||
bool shouldClean = EditorPrefs.GetInt($"{nameof(MSBuildTools)}.{nameof(currentBuildTarget)}") != (int)currentBuildTarget
|
||||
|| EditorPrefs.GetInt($"{nameof(MSBuildTools)}.{nameof(targetFramework)}") != (int)targetFramework
|
||||
|| forceGenerateEverything;
|
||||
|
||||
if (shouldClean)
|
||||
{
|
||||
// We clean up previous build if the EditorPrefs currentBuildTarget or targetFramework is different from current ones.
|
||||
MSBuildProjectBuilder.TryBuildAllProjects(MSBuildProjectBuilder.CleanProfileName);
|
||||
}
|
||||
|
||||
bool doesTokenFileExist = File.Exists(TokenFilePath);
|
||||
|
||||
// We regenerate the common "directory" props file under the following conditions:
|
||||
// - Token file doesn't exist which means editor was just started
|
||||
// - EditorPrefs currentBuildTarget or targetFramework is different from current ones (same as for executing a clean)
|
||||
if (shouldClean || !doesTokenFileExist)
|
||||
{
|
||||
Exporter.GenerateDirectoryPropsFile(UnityProjectInfo);
|
||||
}
|
||||
|
||||
if (!Config.AutoGenerateEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// We regenerate everything if:
|
||||
// - We are forced to
|
||||
// - AutoGenerateEnabled and token file doesn't exist or shouldClean is true
|
||||
if (forceGenerateEverything || (Config.AutoGenerateEnabled && (!doesTokenFileExist || shouldClean)))
|
||||
{
|
||||
RegenerateEverything(true);
|
||||
}
|
||||
|
||||
if (!fileExists)
|
||||
{
|
||||
File.Create(TokenFilePath).Dispose();
|
||||
}
|
||||
if (!doesTokenFileExist)
|
||||
{
|
||||
File.Create(TokenFilePath).Dispose();
|
||||
}
|
||||
|
||||
// Write the current targetframework and build target
|
||||
EditorPrefs.SetInt($"{nameof(MSBuildTools)}.{nameof(currentBuildTarget)}", (int)currentBuildTarget);
|
||||
EditorPrefs.SetInt($"{nameof(MSBuildTools)}.{nameof(targetFramework)}", (int)targetFramework);
|
||||
|
||||
// If we cleaned, now build
|
||||
if (shouldClean)
|
||||
{
|
||||
MSBuildProjectBuilder.TryBuildAllProjects(MSBuildProjectBuilder.BuildProfileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "com.microsoft.msbuildforunity",
|
||||
"version": "0.8.1",
|
||||
"version": "0.8.2",
|
||||
"displayName": "MSBuild for Unity",
|
||||
"description": "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.",
|
||||
"unity": "2018.1",
|
||||
|
|
Загрузка…
Ссылка в новой задаче