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

Support NuGet PackageReference properly in WPF temporary assembly #1786

Closed
wants to merge 4 commits into from

Conversation

rrelyea
Copy link
Contributor

@rrelyea rrelyea commented Nov 3, 2017

Support NuGet PackageReference properly in WPF temporary assembly by enabling .g.targets and .g.props to be properly included, despite the project file name change.

(Right now, just shopping the approach around, and looking for feedback. Need to coordinate with WPF team as well.)

Bug

Fixes: NuGet/Home#5894
Regression: No
If Regression then when did it last work: Never w/ project.json or PackageReference
If Regression then how are we preventing it in future: n/a

Fix

Details:
We're copying GenerateTemporaryTargetAssembly class from PresentationBuildTasks.dll and creating a GenerateTemporaryTargetAssembly2 class.
The temp proj file will no longer be:
.tmp_proj
it will now be:
.

And we'll set _OriginalProjectName msbuild property so that microsoft.common.props/targets can find the .g.props/targets.

There are a set of changes necessary with msbuild as well. (will edit to add link once I create that PR)

Testing/Validation

Tests Added: No
Reason for not adding tests: Will do before final PR
Validation done: made frankenbuild, and tried Nerdbank.GitVersioning

…ling .g.targets and .g.props to be properly included, despite the project file name change.

We're copying GenerateTemporaryTargetAssembly class from PresentationBuildTasks.dll and creating a GenerateTemporaryTargetAssembly2 class.
The temp proj file will no longer be:
<randfilename>.tmp_proj
it will now be:
<randfilename>.<originalProjectExtension>

And  we'll set _OriginalProjectName msbuild property so that microsoft.common.props/targets can find the <origProjectName>.g.props/targets.

There are a set of changes necessary with msbuild as well.
/// ResolveAssemblyReference (RAR) again.
///
/// </summary>
public sealed class GenerateTemporaryTargetAssembly2 : Task
Copy link
Contributor

Choose a reason for hiding this comment

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

This Task wasn't previously OSS, was it? Do we have the necessary approvals to make it so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Yes, will have to deal with license side of this.

//

// GetRandomFileName( ) could return any possible file name and extension, but
// some file externsion has special meaning in MSBUILD system, such as a ".sln"
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: externsion

(even if you copied it from src)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing in next iteration. Yes, was copied.

// Add AssemblyName and IntermediateOutputPath to the global property list
globalProperties[intermediateOutputPathPropertyName] = IntermediateOutputPath;
globalProperties[assemblyNamePropertyName] = AssemblyName;
globalProperties[originalProjectNamePropertyName] = Path.GetFileNameWithoutExtension(CurrentProject);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised to see these are all the global properties that are set. There could be any number of other global properties that were passed to the outer build that could result in this project experiencing a build break when they are dropped. If that's prior behavior of the original task, then I guess we can Won't Fix this as one of the Evils of the WPF inner-build design.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

globalProperties were used for intermediateOutputPathPropertyName, assemblyNamePropertyName. I added originalProjectNamePropertyName
Resolved won't fix due to evil design.

try
{
// Delete the random project file from disk.
File.Delete(randProjPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

wish list: based on an environment variable, skip the step of deleting the random project. so many times I've wished I could inspect and build this file myself when debugging why the inner build fails when the outer build would succeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding code to see if an environment variable of the name "WPF_DoNotDeleteTemporaryProject" has a non-empty/non-null value.

//
// Remove specific items from project file. Every item should be under an ItemGroup.
//
private void RemoveItemsByName(XmlDocument xmlProjectDoc, string sItemName)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a lot I'd like to critique about this method, but I'll forbear since I suspect you just copied it and don't want to change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, copied this method.

XmlDocument xmlProjectDoc = null;

xmlProjectDoc = new XmlDocument();
xmlProjectDoc.Load(CurrentProject);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we loading this as an XmlDocument instead of using the MSBuild construction model? If this is as it was and you're just copying it, then fine. Otherwise if it's new code, IMO we should fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just copying the code with very minor changes.

Rob Relyea added 2 commits November 13, 2017 16:37
* Enable WPF_DoNotDeleteTemporaryProject EnvVar switch to allow an advanced user to keep it around to help debug failures.
@clairernovotny
Copy link

just checking in on the status of this?

@nkolev92
Copy link
Member

nkolev92 commented Feb 6, 2018

Currently no plans to ship within NuGet.

The fix will be shipped along-side MsBuild 15.6 and net472.

@nkolev92 nkolev92 closed this Feb 6, 2018
@clairernovotny
Copy link

That's extremely unfortunate that there's no way to get this out-of-band.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants