Skip to content

Commit

Permalink
Merge pull request #291 from sharwell/no-desktop-assembly
Browse files Browse the repository at this point in the history
Fail the build on reference to Microsoft.CodeAnalysis.Workspaces.Desktop
  • Loading branch information
sharwell authored Apr 3, 2019
2 parents eccb0fd + 7c50080 commit a946678
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/Microsoft.CodeAnalysis.Testing/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project>
<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />

<!--
Microsoft.CodeAnalysis.Workspaces.Desktop is part of Roslyn prior to the 3.0.0 release, but is not included starting
with 3.0.0. This target ensures that even though we compile against an early build of Roslyn (1.0.1), we do not pick
up this dependency in a way that breaks 3.0+ consumers.
-->
<Target Name="RemoveWorkspacesDesktop" AfterTargets="ResolvePackageAssets">
<ItemGroup>
<RuntimeCopyLocalItems Remove="@(RuntimeCopyLocalItems)" Condition="'%(Filename)' == 'Microsoft.CodeAnalysis.Workspaces.Desktop'" />
<ResolvedCompileFileDefinitions Remove="@(ResolvedCompileFileDefinitions)" Condition="'%(Filename)' == 'Microsoft.CodeAnalysis.Workspaces.Desktop'" />
</ItemGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,8 @@ protected virtual Project ApplyCompilationOptions(Project project)
public virtual AdhocWorkspace CreateWorkspace()
{
var exportProvider = ExportProviderFactory.Value.CreateExportProvider();

#if NETSTANDARD1_5 || NETSTANDARD2_0
var host = MefHostServices.Create(exportProvider.AsCompositionContext());
return new AdhocWorkspace(host);
#else
var host = MefV1HostServices.Create(exportProvider.AsExportProvider());
return new AdhocWorkspace(host);
#endif
}

protected abstract CompilationOptions CreateCompilationOptions();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// <auto-generated/>
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if DEBUG

namespace Microsoft.CodeAnalysis
{
/// <summary>
/// This type is part of forcing a build error in the Code Fix assembly if a reference to
/// Microsoft.CodeAnalysis.Workspaces.Desktop is included.
/// </summary>
internal class FileTextLoader { }
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// <auto-generated/>
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if DEBUG

namespace Microsoft.CodeAnalysis
{
/// <summary>
/// This class will fail to compile (CS0419 Ambiguous reference in cref attribute) if the project contains a
/// reference to Microsoft.CodeAnalysis.Workspaces.Desktop.
/// </summary>
/// <see cref="FileTextLoader"/>
internal class EnsureNoWorkspacesDesktopReference
{
}
}

#endif

0 comments on commit a946678

Please sign in to comment.