Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common.targets support for reference assemblies #2039

Merged
merged 17 commits into from
May 19, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<_DocumentationFileProduced>true</_DocumentationFileProduced>
<_DocumentationFileProduced Condition="'$(DocumentationFile)'==''">false</_DocumentationFileProduced>

<!-- Whether or not a reference assembly is produced-->
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are users supposed to use this property to turn ref assemblies off?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To not create them in this project. They'll still be consumed if produced in other projects.

Better names welcome.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not already defined!

<ProduceReferenceAssembly Condition="'$(Deterministic)' == 'true'">true</ProduceReferenceAssembly>
</PropertyGroup>

<PropertyGroup Condition=" '$(OutputPath)' == '' ">
Expand Down Expand Up @@ -281,6 +284,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 @@ -350,6 +355,13 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<FinalDocFile Include="@(DocFileItem->'$(OutDir)%(Filename)%(Extension)')"/>
</ItemGroup>

<ItemGroup Condition="'$(Deterministic)' == 'true'">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs an explicit "no ref asm" off switch, as well as defaulting for Deterministic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition must also apply to $(TargetRefPath).

<!-- TODO: should this be configurable? Default path obeys conventions. -->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking "no", let the user define the item themselves if they want a nonstandard path.

<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 +783,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Name="Build"
Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
DependsOnTargets="$(BuildDependsOn)"
Returns="$(TargetPath)" />
Returns="@(TargetPathWithTargetPlatformMoniker)" />

<!--
============================================================
Expand Down Expand Up @@ -1797,6 +1809,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<TargetPathWithTargetPlatformMoniker Include="$(TargetPath)">
<TargetPlatformMoniker>$(TargetPlatformMoniker)</TargetPlatformMoniker>
<TargetPlatformIdentifier>$(TargetPlatformIdentifier)</TargetPlatformIdentifier>
<ReferenceAssembly Condition="'$(ProduceReferenceAssembly)' != ''">$(TargetRefPath)</ReferenceAssembly>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this condition be if ProduceReferenceAssembly == true? Otherwise if false we'll still be setting this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 😳

</TargetPathWithTargetPlatformMoniker>
</ItemGroup>
</Target>
Expand Down Expand Up @@ -2015,8 +2028,21 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Output TaskParameter="FilesWritten" ItemName="FileWrites"/>
<Output TaskParameter="DependsOnSystemRuntime" PropertyName="DependsOnSystemRuntime"/>
</ResolveAssemblyReference>

<ItemGroup>
<ReferencePathWithRefAssemblies Include="@(ReferencePath->'%(ReferenceAssembly)')" />
</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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is magic. ✨

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alas, it was too magic: #2165

</ReferencePath>
</ItemDefinitionGroup>

<!--
====================================================================================================

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

</Copy>

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

<Output TaskParameter="DestinationPath" ItemName="ReferenceAssembly"/>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add output to the outputs-of-this-project item so clean works right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be in FileWrites? It probably needs to be in this item group almost always otherwise it will get deleted in between builds right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that after my last changes Clean now deletes the ref assembly from both bin and obj, and IncrementalClean leaves it alone. Is there another scenario to test?

<Output TaskParameter="DestinationFiles" 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 @@ -4468,6 +4506,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<!--Record the main compile outputs.-->
<ItemGroup>
<FileWrites Include="@(IntermediateAssembly)" Condition="Exists('@(IntermediateAssembly)')"/>
<FileWrites Include="@(IntermediateRefAssembly)" Condition="'@(IntermediateRefAssembly)' != '' 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)' != ''" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the expected behavior if the user has a newer version of the Roslyn package installed? I believe that package does UsingTasks on Csc/Vbc so those get overridden. Should we be doing the UsingTask too there so that way an upgrade also means you get a newer version here? (cc @jcouv)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent catch! I added it to the Roslyn package props in dotnet/roslyn@ae50fe8

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 😄

</Project>