-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Restore PackageReferences in temporary assembly projects to import build extensions #1056
Conversation
@ryalanms Thanks for fixing this issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some debug-only code in the three related building tasks.
I use this method to debug my custom building tasks, too. But I think it shouldn't be merged into the release-version code.
...PresentationBuildTasks/Microsoft/Build/Tasks/Windows/CreateTemporaryTargetAssemblyProject.cs
Outdated
Show resolved
Hide resolved
.../src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs
Outdated
Show resolved
Hide resolved
...DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/RunProjectBuildTarget.cs
Outdated
Show resolved
Hide resolved
Thanks for reviewing, @walterlv. After this fix is in, there shouldn't be any need to use custom code to get the build extensions in PackageReferences to work in user code. |
69adf43
to
1e974a0
Compare
Note that this will fail to build with duplicate imports until the Arcade SDK change is merged and picked up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good, I like 3 tasks better than pivoting on params.
Arcade just merged the change. |
@@ -1,3 +1,13 @@ | |||
Compat issues with assembly PresentationBuildTasks: | |||
MembersMustExist : Member 'Microsoft.Build.Tasks.Windows.GenerateTemporaryTargetAssembly.CompileTypeName.get()' does not exist in the implementation but it does exist in the contract. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a larger unrelated questions we should try to address - namely whether ref-assembly for PresentationBuildTasks needs to be rolled into the ref-pack for .NET Core 3.0.
@@ -20,6 +20,8 @@ | |||
<UsingTask TaskName="Microsoft.Build.Tasks.Windows.FileClassifier" AssemblyFile="$(_PresentationBuildTasksAssembly)" /> | |||
<UsingTask TaskName="Microsoft.Build.Tasks.Windows.MarkupCompilePass2" AssemblyFile="$(_PresentationBuildTasksAssembly)" /> | |||
<UsingTask TaskName="Microsoft.Build.Tasks.Windows.GenerateTemporaryTargetAssembly" AssemblyFile="$(_PresentationBuildTasksAssembly)" /> | |||
<UsingTask TaskName="Microsoft.Build.Tasks.Windows.CreateTemporaryTargetAssemblyProject" AssemblyFile="$(_PresentationBuildTasksAssembly)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you chose CreateTemporaryTargetAssemblyProject
, instead of calling the task GenerateTemporaryTargetAssemblyProject
and keep naming in line with previous task names?
@@ -380,6 +382,8 @@ | |||
<PropertyGroup> | |||
|
|||
<MarkupCompilePass2ForMainAssemblyDependsOn> | |||
CreateTemporaryTargetAssemblyProject; | |||
RestoreTemporaryTargetAssemblyProject; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend renaming this target as "RunRestoreTargetOnTemporaryTargetAssemblyProject"
|
||
<RunProjectBuildTarget | ||
ProjectName="$(_TemporaryTargetAssemblyProjectName)" | ||
BuildTarget="Restore" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a pattern similar to that in <Target Name="_CompileTemporaryAssembly" DependsOnTargets="BuildOnlySettings;ResolveKeySource;CoreCompile" />
and <_CompileTargetNameForLocalType Condition="'$(_CompileTargetNameForLocalType)' == ''">_CompileTemporaryAssembly</_CompileTargetNameForLocalType>
used in GenerateTemporaryTargetAssembly
using MS.Utility; | ||
using MS.Internal.Tasks; | ||
|
||
// Since we disable PreSharp warnings in this file, PreSharp warning is unknown to C# compiler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this and related suppressions - we don't really use PreSharp any more
// | ||
if (nodeGroup.HasChildNodes) | ||
{ | ||
ArrayList itemToRemove = new ArrayList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use ArrayList
- instead use List<object>
// | ||
// Continue the loop for the next ItemGroup. | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excess blank line
} | ||
|
||
} // end of "for i" statement. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excess blank line
/// </summary> | ||
public sealed class RunProjectBuildTarget : Task | ||
{ | ||
#region Constructors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use regions in new code
using MS.Utility; | ||
using MS.Internal.Tasks; | ||
|
||
// Since we disable PreSharp warnings in this file, PreSharp warning is unknown to C# compiler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use PreSharp - remove comment and related warning suppressions
The approach and the fix looks good to me overall. Given the overall level of churn, I'm hesitant to merge this so close to Preview 7 (check-ins close at noon tomorrow for WPF). I don't see clear reasons why this change should cause regressions. The approach is sound and I think the change looks good to me overall. That said, the general complexity of the fix makes me think that it is likely to bring with it a slightly higher possibility of bugs. I'd rather fork off master to preview/3.0 (which happens on in two days on 6/26), and and then merge this into master for Preview 8 (so we would get early feedback on P8 builds). I've spoken with @ryalanms and he agrees that waiting for 2 days is reasonable. Marking as NO MERGE for now. |
Removing NO MERGE since #1100 is completed. |
Are you initiating a restore during the build? That is not allowed. It breaks the promise of build --no-restore, and will also mess with VS that handles restore differently than restore target. |
cc @davkean |
This seems risky. If there's any evaluation change in generated project that ends up changing a PackageReference it could still hit the network. |
Closing this, since we ended up taking a different implementation. Thanks. |
The temporary project is not getting props and targets files (build extension files) from PackageReferences defined in their parent project. This is causing failures in referenced packages that rely on build extensions (e.g., Google Protocol Buffers) to perform pre-compile tasks, such as code generation.
Several options were considered, including consuming the generated props and targets that include the PackageReferences props/targets from the outer parent project, as the parent project
Restore
has already run and includes identical PackageReferences. However, we opted to runRestore
directly on the temporary project instead, which allowed a fix without changes to external build files (other than a minor change to the Arcade SDK). There are now twoRestore
operations: one for the parent project and one for the temporary project. Note thatRestore
will not re-download packages but will generate the assets file, targets file, and props file. These files include imports for build extensions in the PackageReferences.These tasks could easily be condensed in to a single parameterized task, but breaking the steps in to three made a logs easier to read and improved debugging. There are now three tasks:
CreateTemporaryTargetAssemblyProject
RestoreTemporaryTargetAssemblyProject
(which callsRunProjectBuildTarget
withRestore
)GenerateTemporaryTargetAssembly
The first task creates a temporary project with random component in the name from the outer parent project.
RestoreTemporaryTargetAssemblyProject
consumes the temporary project and runsRestore
, generating assets, .props, and .targets files that include imports to any build extensions inside PackageReferences. These files are then consumed inGenerateTemporaryTargetAssembly
as part of thenormal build process for the temporary project.
Note that there is an Arcade SDK targets file change that needs to be coordinated with this change. Workaround.props needs to be modified to remove a temporary workaround for the lack of PackageReference support to prevent duplicate import errors. dotnet/arcade#3127
(APICompat was re-baselined to account for the public API surface changes in PresentationBuildTasks.)