Skip to content

Commit b4cdb07

Browse files
sailroGitHub Enterprise
authored andcommitted
Merge pull request #189 from unity/obj-output
Prevent circular dependency errors
2 parents c958d3c + f98ab07 commit b4cdb07

File tree

6 files changed

+32
-17
lines changed

6 files changed

+32
-17
lines changed

Packages/com.unity.ide.visualstudio.tests/Tests/Editor/AssemblyNameProviderTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public void SetUp()
3030
m_AssemblyNameProvider.ResetProjectGenerationFlag();
3131
}
3232

33-
[TestCase(@"Temp\Bin\Debug\", "AssemblyName", "AssemblyName")]
34-
[TestCase(@"Temp\Bin\Debug\", "My.Player.AssemblyName", "My.Player.AssemblyName")]
35-
[TestCase(@"Temp\Bin\Debug\", "AssemblyName.Player", "AssemblyName.Player")]
36-
[TestCase(@"Temp\Bin\Debug\Player\", "AssemblyName", "AssemblyName.Player")]
37-
[TestCase(@"Temp\Bin\Debug\Player\", "AssemblyName.Player", "AssemblyName.Player.Player")]
33+
[TestCase(@"Temp\bin\Debug\", "AssemblyName", "AssemblyName")]
34+
[TestCase(@"Temp\bin\Debug\", "My.Player.AssemblyName", "My.Player.AssemblyName")]
35+
[TestCase(@"Temp\bin\Debug\", "AssemblyName.Player", "AssemblyName.Player")]
36+
[TestCase(@"Temp\bin\Debug\Player\", "AssemblyName", "AssemblyName.Player")]
37+
[TestCase(@"Temp\bin\Debug\Player\", "AssemblyName.Player", "AssemblyName.Player.Player")]
3838
public void GetOutputPath_ReturnsPlayerAndeditorOutputPath(string assemblyOutputPath, string assemblyName, string expectedAssemblyName)
3939
{
40-
Assert.AreEqual(expectedAssemblyName, m_AssemblyNameProvider.GetAssemblyName(assemblyOutputPath, assemblyName));
40+
Assert.AreEqual(expectedAssemblyName, m_AssemblyNameProvider.GetAssemblyName(assemblyOutputPath.NormalizePathSeparators(), assemblyName));
4141
}
4242

4343
[Test]
@@ -49,7 +49,7 @@ public void AllEditorAssemblies_AreCollected()
4949

5050
foreach (Assembly editorAssembly in editorAssemblies)
5151
{
52-
Assert.IsTrue(collectedAssemblies.Any(assembly => assembly.name == editorAssembly.name && assembly.outputPath == @"Temp\Bin\Debug\"), $"{editorAssembly.name}: was not found in collection.");
52+
Assert.IsTrue(collectedAssemblies.Any(assembly => assembly.name == editorAssembly.name && assembly.outputPath == AssemblyNameProvider.AssemblyOutput), $"{editorAssembly.name}: was not found in collection.");
5353
}
5454
}
5555

@@ -91,7 +91,7 @@ public void PlayerAssemblies_AreNotCollected_BeforeToggling()
9191

9292
foreach (Assembly playerAssembly in playerAssemblies)
9393
{
94-
Assert.IsFalse(collectedAssemblies.Any(assembly => assembly.name == playerAssembly.name && assembly.outputPath == @"Temp\Bin\Debug\Player\"), $"{playerAssembly.name}: was found in collection.");
94+
Assert.IsFalse(collectedAssemblies.Any(assembly => assembly.name == playerAssembly.name && assembly.outputPath == AssemblyNameProvider.PlayerAssemblyOutput), $"{playerAssembly.name}: was found in collection.");
9595
}
9696
}
9797

@@ -106,7 +106,7 @@ public void AllPlayerAssemblies_AreCollected_AfterToggling()
106106

107107
foreach (Assembly playerAssembly in playerAssemblies)
108108
{
109-
Assert.IsTrue(collectedAssemblies.Any(assembly => assembly.name == playerAssembly.name && assembly.outputPath == @"Temp\Bin\Debug\Player\"), $"{playerAssembly.name}: was not found in collection.");
109+
Assert.IsTrue(collectedAssemblies.Any(assembly => assembly.name == playerAssembly.name && assembly.outputPath == AssemblyNameProvider.PlayerAssemblyOutput), $"{playerAssembly.name}: was not found in collection.");
110110
}
111111
}
112112

Packages/com.unity.ide.visualstudio.tests/Tests/Editor/CSProjectTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void DefaultSyncSettings_WhenSynced_CreatesProjectFileFromDefaultTemplate
156156
" <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">",
157157
" <DebugType>pdbonly</DebugType>",
158158
" <Optimize>true</Optimize>",
159-
" <OutputPath>Temp\\bin\\Release\\</OutputPath>",
159+
$" <OutputPath>{@"Temp\bin\Release\".NormalizePathSeparators()}</OutputPath>",
160160
" <ErrorReport>prompt</ErrorReport>",
161161
" <WarningLevel>4</WarningLevel>",
162162
" <NoWarn>0169;USG0001</NoWarn>",
@@ -183,7 +183,7 @@ public void DefaultSyncSettings_WhenSynced_CreatesProjectFileFromDefaultTemplate
183183
" </ItemGroup>",
184184
" <ItemGroup>",
185185
" </ItemGroup>",
186-
" <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />",
186+
$" <Import Project=\"{@"$(MSBuildToolsPath)\Microsoft.CSharp.targets".NormalizePathSeparators()}\" />",
187187
" <Target Name=\"GenerateTargetFrameworkMonikerAttribute\" />",
188188
" <!-- To modify your build process, add your task inside one of the targets below and uncomment it.",
189189
" Other similar extension points exist, see Microsoft.Common.targets.",

Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/AssemblyNameProvider.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,18 @@ public string GetAssemblyNameFromScriptPath(string path)
6161
return CompilationPipeline.GetAssemblyNameFromScriptPath(path);
6262
}
6363

64+
internal static readonly string AssemblyOutput = @"Temp\bin\Debug\".NormalizePathSeparators();
65+
internal static readonly string PlayerAssemblyOutput = @"Temp\bin\Debug\Player\".NormalizePathSeparators();
66+
6467
public IEnumerable<Assembly> GetAssemblies(Func<string, bool> shouldFileBePartOfSolution)
6568
{
66-
IEnumerable<Assembly> assemblies = GetAssembliesByType(AssembliesType.Editor, shouldFileBePartOfSolution, @"Temp\Bin\Debug\");
69+
IEnumerable<Assembly> assemblies = GetAssembliesByType(AssembliesType.Editor, shouldFileBePartOfSolution, AssemblyOutput);
6770

6871
if (!ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.PlayerAssemblies))
6972
{
7073
return assemblies;
7174
}
72-
var playerAssemblies = GetAssembliesByType(AssembliesType.Player, shouldFileBePartOfSolution, @"Temp\Bin\Debug\Player\");
75+
var playerAssemblies = GetAssembliesByType(AssembliesType.Player, shouldFileBePartOfSolution, PlayerAssemblyOutput);
7376
return assemblies.Concat(playerAssemblies);
7477
}
7578

@@ -98,7 +101,8 @@ private static IEnumerable<Assembly> GetAssembliesByType(AssembliesType type, Fu
98101

99102
public string GetCompileOutputPath(string assemblyName)
100103
{
101-
return assemblyName.EndsWith(".Player", StringComparison.Ordinal) ? @"Temp\Bin\Debug\Player\" : @"Temp\Bin\Debug\";
104+
// We need to keep this one for API surface check (AssemblyNameProvider is public), but not used anymore
105+
throw new NotImplementedException();
102106
}
103107

104108
public IEnumerable<string> GetAllAssetPaths()
@@ -207,7 +211,10 @@ public void ResetProjectGenerationFlag()
207211

208212
public string GetAssemblyName(string assemblyOutputPath, string assemblyName)
209213
{
210-
return assemblyOutputPath.EndsWith(@"\Player\", StringComparison.Ordinal) ? assemblyName + ".Player" : assemblyName;
214+
if (assemblyOutputPath == PlayerAssemblyOutput)
215+
return assemblyName + ".Player";
216+
217+
return assemblyName;
211218
}
212219
}
213220
}

Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/LegacyStyleProjectGeneration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ internal override void AppendProjectReference(Assembly assembly, Assembly refere
8484
internal override void GetProjectFooter(StringBuilder footerBuilder)
8585
{
8686
footerBuilder.Append(string.Join(k_WindowsNewline,
87-
@" <Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />",
87+
$" <Import Project=\"{@"$(MSBuildToolsPath)\Microsoft.CSharp.targets".NormalizePathSeparators()}\" />",
8888
@" <Target Name=""GenerateTargetFrameworkMonikerAttribute"" />",
8989
@" <!-- To modify your build process, add your task inside one of the targets below and uncomment it.",
9090
@" Other similar extension points exist, see Microsoft.Common.targets.",

Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ internal static void GetProjectHeaderConfigurations(ProjectProperties properties
786786
headerBuilder.Append(@" <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "">").Append(k_WindowsNewline);
787787
headerBuilder.Append(@" <DebugType>pdbonly</DebugType>").Append(k_WindowsNewline);
788788
headerBuilder.Append(@" <Optimize>true</Optimize>").Append(k_WindowsNewline);
789-
headerBuilder.Append(@" <OutputPath>Temp\bin\Release\</OutputPath>").Append(k_WindowsNewline);
789+
headerBuilder.Append($" <OutputPath>{@"Temp\bin\Release\".NormalizePathSeparators()}</OutputPath>").Append(k_WindowsNewline);
790790
headerBuilder.Append(@" <ErrorReport>prompt</ErrorReport>").Append(k_WindowsNewline);
791791
headerBuilder.Append(@" <WarningLevel>4</WarningLevel>").Append(k_WindowsNewline);
792792
headerBuilder.Append(@" <NoWarn>").Append(NoWarn).Append("</NoWarn>").Append(k_WindowsNewline);

Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/SdkStyleProjectGeneration.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ internal override void GetProjectHeader(ProjectProperties properties, out String
5555
headerBuilder.Append(@"<Project ToolsVersion=""Current"">").Append(k_WindowsNewline);
5656
headerBuilder.Append(@" <!-- Generated file, do not modify, your changes will be overwritten (use AssetPostprocessor.OnGeneratedCSProject) -->").Append(k_WindowsNewline);
5757

58+
// Prevent circular dependency issues see https://github.com/microsoft/vscode-dotnettools/issues/401
59+
// We need a dedicated subfolder for each project in obj, else depending on the build order, nuget cache files could be overwritten
60+
// We need to do this before common.props, else we'll have a MSB3539 The value of the property "BaseIntermediateOutputPath" was modified after it was used by MSBuild
61+
headerBuilder.Append(@" <PropertyGroup>").Append(k_WindowsNewline);
62+
headerBuilder.Append($" <BaseIntermediateOutputPath>{@"Temp\obj\$(Configuration)\$(MSBuildProjectName)".NormalizePathSeparators()}</BaseIntermediateOutputPath>").Append(k_WindowsNewline);
63+
headerBuilder.Append(@" <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>").Append(k_WindowsNewline);
64+
headerBuilder.Append(@" </PropertyGroup>").Append(k_WindowsNewline);
65+
5866
// Supported capabilities
5967
GetCapabilityBlock(headerBuilder, "Sdk.props", "Include", SupportedCapabilities);
6068

0 commit comments

Comments
 (0)