Skip to content

Commit

Permalink
Common.targets support for reference assemblies (#2039)
Browse files Browse the repository at this point in the history
Provides an item, `ReferencePathWithInterfaceOnlyAssemblies`, that
consists of the reference (interface-only) versions of assemblies where
available, allowing a consuming task to be incrementally up-to-date
after implementation-only changes have been made to a reference.

When `%(ReferenceAssembly)` metadata is unavailable for a given
reference, the new item contains the implementation assembly directly.

Additionally creates a new output item for the current project's
reference assembly when `$(ProduceReferenceAssembly)` is true. If this
is created, it is copied to the output directory using the new
`CopyRefAssembly` task, which copies only if the ref assembly is
different from the current file. If present, the ref asm is passed to
the project's consumes in metadata.

Introduce $(CompileUsingReferenceAssemblies), which can avoid
passing reference assemblies to the compiler when set to false.
This is not expected to be commonly used.

IDE fast up-to-date checks need to be able to compare timestamps on
_both_ the reference assembly (to see if a recompile is needed) and the
implementation assembly (because it needs to be copied to an output
location). Provide OriginalPathmetadata on the adjusted references
that points back to the implementation assembly if a ref assembly was
found.

When a project both uses and produces reference assemblies, its primary
output assembly might be up to date while (transitive) references need
to be copied to its output directory. This case fooled the Visual Studio
Fast Up-To-Date check, because the transitive dependencies aren't listed
as project inputs (because design-time builds disable RAR's
FindDependencies for performance reasons).

To account for this, introduce a new file that is updated whenever
_CopyFilesMarkedCopyLocal does actual work, pass it along as part of the
project's output, and consider it a project input for the FUTD check.

See #1986, dotnet/roslyn#2184.
  • Loading branch information
rainersigwald authored May 19, 2017
1 parent 67954cb commit e3a3d69
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
92 changes: 90 additions & 2 deletions src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<_DocumentationFileProduced>true</_DocumentationFileProduced>
<_DocumentationFileProduced Condition="'$(DocumentationFile)'==''">false</_DocumentationFileProduced>

<!-- Whether or not a reference assembly is produced. -->
<ProduceReferenceAssembly Condition="'$(ProduceReferenceAssembly)' == ''">false</ProduceReferenceAssembly>
</PropertyGroup>

<PropertyGroup Condition=" '$(OutputPath)' == '' ">
Expand Down Expand Up @@ -281,6 +283,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<!-- Example, c:\MyProjects\MyProject\bin\debug\MyAssembly.dll -->
<TargetPath Condition=" '$(TargetPath)' == '' ">$(TargetDir)$(TargetFileName)</TargetPath>

<TargetRefPath Condition=" '$(TargetRefPath)' == '' and '$(ProduceReferenceAssembly)' == 'true' ">$([MSBuild]::NormalizePath($(TargetDir), 'ref', $(TargetFileName)))</TargetRefPath>

<!-- Example, c:\MyProjects\MyProject\ -->
<ProjectDir Condition=" '$(ProjectDir)' == '' ">$(MSBuildProjectDirectory)\</ProjectDir>

Expand Down Expand Up @@ -344,12 +348,19 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<PropertyGroup>
<IntermediateOutputPath Condition="!HasTrailingSlash('$(IntermediateOutputPath)')">$(IntermediateOutputPath)\</IntermediateOutputPath>
<_GenerateBindingRedirectsIntermediateAppConfig>$(IntermediateOutputPath)$(MSBuildProjectFile).$(TargetFileName).config</_GenerateBindingRedirectsIntermediateAppConfig>
<CopyUpToDateMarker Condition="'$(ProduceReferenceAssembly)' == 'true'">$([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', '$(IntermediateOutputPath)', '$(MSBuildProjectFile).CopyComplete'))</CopyUpToDateMarker>
</PropertyGroup>
<ItemGroup>
<IntermediateAssembly Include="$(IntermediateOutputPath)$(TargetName)$(TargetExt)"/>
<FinalDocFile Include="@(DocFileItem->'$(OutDir)%(Filename)%(Extension)')"/>
</ItemGroup>

<ItemGroup Condition="'$(ProduceReferenceAssembly)' == 'true'">
<IntermediateRefAssembly Include="$(IntermediateOutputPath)ref\$(TargetName)$(TargetExt)" Condition="'@(IntermediateRefAssembly)' == ''" />
<CreateDirectory Include="@(IntermediateRefAssembly->'%(RootDir)%(Directory)')" />
<CreateDirectory Include="$(OutDir)ref" />
</ItemGroup>

<ItemGroup Condition="'$(_DebugSymbolsProduced)' == 'true'">
<_DebugSymbolsIntermediatePath Include="$(IntermediateOutputPath)$(TargetName).compile.pdb" Condition="'$(OutputType)' == 'winmdobj' and '@(_DebugSymbolsIntermediatePath)' == ''"/>
<_DebugSymbolsIntermediatePath Include="$(IntermediateOutputPath)$(TargetName).pdb" Condition="'$(OutputType)' != 'winmdobj' and '@(_DebugSymbolsIntermediatePath)' == ''"/>
Expand Down Expand Up @@ -771,7 +782,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Name="Build"
Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
DependsOnTargets="$(BuildDependsOn)"
Returns="$(TargetPath)" />
Returns="@(TargetPathWithTargetPlatformMoniker)" />

<!--
============================================================
Expand Down Expand Up @@ -1360,9 +1371,15 @@ Copyright (C) Microsoft Corporation. All rights reserved.
AfterResolveReferences
</ResolveReferencesDependsOn>
</PropertyGroup>

<!-- FindReferenceAssembliesForReferences needs to see a fully-populated @(ReferencePath),
so it should run after all of the subcomponents of ResolveReferences, including
user overrides of AfterResolveReferences and targets added by appending to
$(ResolveReferencesDependsOn) (like ImplicitlyExpandDesignTimeFacades). So list it
last explicitly, rather than adding it to the property. -->
<Target
Name="ResolveReferences"
DependsOnTargets="$(ResolveReferencesDependsOn)"/>
DependsOnTargets="$(ResolveReferencesDependsOn);FindReferenceAssembliesForReferences"/>

<!--
============================================================
Expand Down Expand Up @@ -1797,6 +1814,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<TargetPathWithTargetPlatformMoniker Include="$(TargetPath)">
<TargetPlatformMoniker>$(TargetPlatformMoniker)</TargetPlatformMoniker>
<TargetPlatformIdentifier>$(TargetPlatformIdentifier)</TargetPlatformIdentifier>
<ReferenceAssembly Condition="'$(ProduceReferenceAssembly)' == 'true'">$(TargetRefPath)</ReferenceAssembly>
<CopyUpToDateMarker Condition="'$(ProduceReferenceAssembly)' == 'true'">$(CopyUpToDateMarker)</CopyUpToDateMarker>
</TargetPathWithTargetPlatformMoniker>
</ItemGroup>
</Target>
Expand Down Expand Up @@ -2011,12 +2030,59 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Output TaskParameter="SerializationAssemblyFiles" ItemName="_ReferenceSerializationAssemblyPaths"/>
<Output TaskParameter="ScatterFiles" ItemName="_ReferenceScatterPaths"/>
<Output TaskParameter="CopyLocalFiles" ItemName="ReferenceCopyLocalPaths"/>
<!-- Indicate to the IDE that updated (possibly transitive) references should trigger
an (incremental) build. -->
<Output TaskParameter="CopyLocalFiles" ItemName="UpToDateCheckInput"/>
<Output TaskParameter="SuggestedRedirects" ItemName="SuggestedBindingRedirects"/>
<Output TaskParameter="FilesWritten" ItemName="FileWrites"/>
<Output TaskParameter="DependsOnSystemRuntime" PropertyName="DependsOnSystemRuntime"/>
</ResolveAssemblyReference>
</Target>

<!--
============================================================
FindReferenceAssembliesForReferences
Given the list of references, create a list of assemblies to pass to the compiler that
includes reference assemblies rather than implementation assemblies where possible.
[IN]
@(ReferencePath) - List of assembly references as resolved paths with ReferenceAssembly metadata
[OUT]
@(ReferencePathWithRefAssemblies) - Paths to resolved reference (or implementation) assemblies.
============================================================
-->
<Target Name="FindReferenceAssembliesForReferences"
DependsOnTargets="$(ResolveReferencesDependsOn)">
<ItemGroup>
<ReferencePathWithRefAssemblies Include="@(ReferencePath->'%(ReferenceAssembly)')"
Condition="'$(CompileUsingReferenceAssemblies)' != 'false'">
<OriginalPath Condition="'%(ReferencePath.Identity)' != '@(ReferencePath->'%(ReferenceAssembly)')'">%(ReferencePath.Identity)</OriginalPath>
</ReferencePathWithRefAssemblies>
<ReferencePathWithRefAssemblies Include="@(ReferencePath)"
Condition="'$(CompileUsingReferenceAssemblies)' == 'false'" />

<!-- The project system normally looks only at the inputs to the compiler in its
fast up-to-date check, but if the implementation assembly of a ref is stale
we still want to rerun to ensure copies, etc. happen. -->
<!-- The remote project might not have done anything to _its own_ assemblies, but
still need to invalidate the fast up-to-date check in projects that depend on
it because it has brought along a new implementation of one of its references. -->
<UpToDateCheckInput Include="@(ReferencePathWithRefAssemblies->'%(CopyUpToDateMarker)')" />
</ItemGroup>
</Target>

<ItemDefinitionGroup>
<!-- Reference assemblies are not produced in all cases, but it's easier to consume them
if this metadatum is always populated. This item definition ensures that it points
to the implementation assembly unless specified. -->
<ReferencePath>
<ReferenceAssembly>%(FullPath)</ReferenceAssembly>
</ReferencePath>
</ItemDefinitionGroup>

<!--
====================================================================================================
Expand Down Expand Up @@ -4007,6 +4073,18 @@ Copyright (C) Microsoft Corporation. All rights reserved.

</Copy>

<!-- Copy the reference assembly build product (.dll or .exe). -->
<CopyRefAssembly
SourcePath="@(IntermediateRefAssembly)"
DestinationPath="$(TargetRefPath)"
Condition="'$(ProduceReferenceAssembly)' == 'true' and '$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'"
>

<Output TaskParameter="DestinationPath" ItemName="ReferenceAssembly"/>
<Output TaskParameter="DestinationPath" ItemName="FileWrites"/>

</CopyRefAssembly>

<Message Importance="High" Text="$(MSBuildProjectName) -&gt; @(MainAssembly->'%(FullPath)')" Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)'!='true'" />

<!-- Copy the additional modules. -->
Expand Down Expand Up @@ -4162,9 +4240,18 @@ Copyright (C) Microsoft Corporation. All rights reserved.
>

<Output TaskParameter="DestinationFiles" ItemName="FileWritesShareable"/>
<Output TaskParameter="CopiedFiles" ItemName="ReferencesCopiedInThisBuild"/>

</Copy>

<!-- If this project produces reference assemblies *and* copied (possibly transitive)
references on this build, subsequent builds of projects that depend on it must
not be considered up to date, so touch this marker file that is considered an
input to projects that reference this one. -->
<Touch Files="$(CopyUpToDateMarker)"
AlwaysCreate="true"
Condition="'$(ProduceReferenceAssembly)' == 'true' and '@(ReferencesCopiedInThisBuild)' != ''" />

</Target>

<!--
Expand Down Expand Up @@ -4468,6 +4555,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<!--Record the main compile outputs.-->
<ItemGroup>
<FileWrites Include="@(IntermediateAssembly)" Condition="Exists('@(IntermediateAssembly)')"/>
<FileWrites Include="@(IntermediateRefAssembly)" Condition="'$(ProduceReferenceAssembly)' == 'true' and Exists('@(IntermediateRefAssembly)')"/>
</ItemGroup>

<!-- Record the .xml if one was produced. -->
Expand Down
1 change: 1 addition & 0 deletions src/Tasks/Microsoft.Common.tasks
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,6 @@
<!-- Roslyn tasks are now in an assembly owned and shipped by Roslyn -->
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Csc" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" Condition="'$(MSBuildAssemblyVersion)' != ''" />
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" Condition="'$(MSBuildAssemblyVersion)' != ''" />
<UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly" AssemblyFile="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" Condition="'$(MSBuildAssemblyVersion)' != ''" />
</Project>

0 comments on commit e3a3d69

Please sign in to comment.