Skip to content

Commit

Permalink
Introduce ReferencePathWithRefAssemblies parameter to CoreCompile tar…
Browse files Browse the repository at this point in the history
…get, and shim (#19146)

* Use refasm-only items for compilation

Use the new item provided by common targets to avoid recompiling a
project when a reference has changed only in implementation, not
interface.

Include a shim so that these targets can continue to work on older
MSBuild distributions. That keeps the NuGet-package-for-downlevel
scenario working, as well as making an easy transition period to the new
logic.

Requires dotnet/msbuild#2039 to enable end-to-end use of reference
assemblies, but is compatible with earlier MSBuilds (without using
reference assemblies).

* Use CopyRefAssembly from NuGet package

The Microsoft.Net.Compilers package delivers UsingTasks to override the
"standard" ones provided by MSBuild's Microsoft.Common.tasks. That
should include the new CopyRefAssembly.
  • Loading branch information
rainersigwald authored and jcouv committed May 3, 2017
1 parent 32a9e28 commit a255d49
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions build/NuGetAdditionalFiles/Microsoft.Net.Compilers.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
AssemblyFile="$(MSBuildThisFileDirectory)..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll" />
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc"
AssemblyFile="$(MSBuildThisFileDirectory)..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll" />
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly"
AssemblyFile="$(MSBuildThisFileDirectory)..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll" />
<PropertyGroup>
<!-- By default don't use the compiler server in Visual Studio. -->
<UseSharedCompilation Condition="'$(UseSharedCompilation)' == ''">false</UseSharedCompilation>
Expand Down
20 changes: 16 additions & 4 deletions src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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 ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ShimReferencePathsWhenCommonTargetsDoesNotUnderstandReferenceAssemblies"
BeforeTargets="CoreCompile"
Condition="'@(ReferencePathWithRefAssemblies)' == ''">
<!-- Common targets should populate this item from dev15.3, but this file
may be used (via NuGet package) on earlier MSBuilds. If the
adjusted-for-reference-assemblies item is not populated, just use
the older item's contents. -->
<ItemGroup>
<ReferencePathWithRefAssemblies Include="@(ReferencePath)" />
</ItemGroup>
</Target>

<Target Name="CoreCompile"
Inputs="$(MSBuildAllProjects);
@(Compile);
@(_CoreCompileResourceInputs);
$(ApplicationIcon);
$(AssemblyOriginatorKeyFile);
@(ReferencePath);
@(ReferencePathWithRefAssemblies);
@(CompiledLicenseFile);
@(LinkResource);
@(EmbeddedDocumentation);
Expand Down Expand Up @@ -38,9 +50,9 @@
</PropertyGroup>

<ItemGroup Condition="'$(TargetingClr2Framework)' == 'true'">
<ReferencePath>
<ReferencePathWithRefAssemblies>
<EmbedInteropTypes />
</ReferencePath>
</ReferencePathWithRefAssemblies>
</ItemGroup>

<PropertyGroup>
Expand Down Expand Up @@ -117,7 +129,7 @@
Prefer32Bit="$(Prefer32Bit)"
PreferredUILang="$(PreferredUILang)"
ProvideCommandLineArgs="$(ProvideCommandLineArgs)"
References="@(ReferencePath)"
References="@(ReferencePathWithRefAssemblies)"
ReportAnalyzer="$(ReportAnalyzer)"
Resources="@(_CoreCompileResourceInputs);@(CompiledLicenseFile)"
ResponseFiles="$(CompilerResponseFile)"
Expand Down
20 changes: 16 additions & 4 deletions src/Compilers/Core/MSBuildTask/Microsoft.VisualBasic.Core.targets
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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 ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ShimReferencePathsWhenCommonTargetsDoesNotUnderstandReferenceAssemblies"
BeforeTargets="CoreCompile"
Condition="'@(ReferencePathWithRefAssemblies)' == ''">
<!-- Common targets should populate this item from dev15.3, but this file
may be used (via NuGet package) on earlier MSBuilds. If the
adjusted-for-reference-assemblies item is not populated, just use
the older item's contents. -->
<ItemGroup>
<ReferencePathWithRefAssemblies Include="@(ReferencePath)" />
</ItemGroup>
</Target>

<Target Name="CoreCompile"
Inputs="$(MSBuildAllProjects);
@(Compile);
@(_CoreCompileResourceInputs);
$(ApplicationIcon);
$(AssemblyOriginatorKeyFile);
@(ReferencePath);
@(ReferencePathWithRefAssemblies);
@(CompiledLicenseFile);
@(LinkResource);
@(EmbeddedDocumentation);
Expand Down Expand Up @@ -36,9 +48,9 @@
</PropertyGroup>

<ItemGroup Condition="'$(TargetingClr2Framework)' == 'true'">
<ReferencePath>
<ReferencePathWithRefAssemblies>
<EmbedInteropTypes />
</ReferencePath>
</ReferencePathWithRefAssemblies>
</ItemGroup>

<!-- Prefer32Bit was introduced in .NET 4.5. Set it to false if we are targeting 4.0 -->
Expand Down Expand Up @@ -109,7 +121,7 @@
Prefer32Bit="$(Prefer32Bit)"
PreferredUILang="$(PreferredUILang)"
ProvideCommandLineArgs="$(ProvideCommandLineArgs)"
References="@(ReferencePath)"
References="@(ReferencePathWithRefAssemblies)"
RemoveIntegerChecks="$(RemoveIntegerChecks)"
ReportAnalyzer="$(ReportAnalyzer)"
Resources="@(_CoreCompileResourceInputs);@(CompiledLicenseFile)"
Expand Down

0 comments on commit a255d49

Please sign in to comment.