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

Add BaseOutputPath to common targets #5238

Merged
merged 7 commits into from
Dec 7, 2020
Merged

Add BaseOutputPath to common targets #5238

merged 7 commits into from
Dec 7, 2020

Conversation

Nirmal4G
Copy link
Contributor

@Nirmal4G Nirmal4G commented Apr 5, 2020

While this is not officially supported on non-sdk projects, NuGet Pack targets need a common output path to put '.nupkg' across both type of projects.

Required for NuGet/Home#9234 in PR NuGet/NuGet.Client#3270

Also Fixes #1664

@Nirmal4G
Copy link
Contributor Author

Nirmal4G commented Apr 12, 2020

I don't know who to tag. So, @rainersigwald NuGet Pack target needs this. Can you or anyone from the team take a look at this?

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

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

Team triage: we're amenable in theory to taking this in 16.7/SDK 3.1.400.

src/Tasks/Microsoft.Common.CurrentVersion.targets Outdated Show resolved Hide resolved
src/Tasks/Microsoft.Common.CurrentVersion.targets Outdated Show resolved Hide resolved
src/Tasks/Microsoft.Common.CurrentVersion.targets Outdated Show resolved Hide resolved
Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

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

I appear to have written up comments but not published them. Sorry!

src/Tasks/Microsoft.Common.CurrentVersion.targets Outdated Show resolved Hide resolved
src/Tasks/Microsoft.Common.CurrentVersion.targets Outdated Show resolved Hide resolved
@Nirmal4G Nirmal4G marked this pull request as draft June 10, 2020 18:55
@Nirmal4G Nirmal4G marked this pull request as ready for review June 13, 2020 12:10
@Nirmal4G
Copy link
Contributor Author

Did a little bit of refactoring to place all the output logic in one place. Other than that, only changes include what you have suggested: Using *OutputPath properties to fallback to legacy Configuration/Platfrom check. That's the last commit.

Should I add tests for the *OutputPath behaviors? If so, then, Where are the tests for the OutputPath?

@rainersigwald
Copy link
Member

rainersigwald commented Jul 17, 2020

I think this looks good to go (with the minor changes that are outstanding). Would you mind resolving conflicts?

@Nirmal4G
Copy link
Contributor Author

When I tested the above logic with and without Common targets, there's a noticeable difference of around 700ms-1s delay when using property functions. This is observed with running the test project again and again in Command Prompt and WSL manually. Is there any guide/tool to properly profile MSBuild builds?

I have tested the above logic with

  1. \, /
  2. Path.Join
  3. Path.Combine
  4. NormalizeDirectory

The NormalizeDirectory/NormalizePath doesn't always generate paths under MSBuildProjectDirectory. Is this Intentional?

Behaviour of NormalizeDirectory
D:\Projects\Work\Repros>msbuild Test.proj -p:Configuration=C:Debug

Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 18-07-2020 08:30:16 PM.
Project "D:\Projects\Work\Repros\Test.proj" on node 1 (default targets).
Test:
  MSBuildToolsVersion: Current
  MSBuildToolsPath:    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin
  MSBuildProjectDirectory: D:\Projects\Work\Repros
  BaseOutputPath: bin\
  BaseIntermediateOutputPath: obj\
  OutputPath: C:\Program Files (x86)\Microsoft Visual Studio\Installer\Debug\
  IntermediateOutputPath: C:\Program Files (x86)\Microsoft Visual Studio\Installer\Debug\
Done Building Project "D:\Projects\Work\Repros\Test.proj" (default targets).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.61
Behaviour of Path.Combine
D:\Projects\Work\Repros>msbuild Test.proj -p:Configuration=C:Debug

Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 18-07-2020 08:33:25 PM.
Project "D:\Projects\Work\Repros\Test.proj" on node 1 (default targets).
Test:
  MSBuildToolsVersion: Current
  MSBuildToolsPath:    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin
  MSBuildProjectDirectory: D:\Projects\Work\Repros
  BaseOutputPath: bin\
  BaseIntermediateOutputPath: obj\
  OutputPath: C:Debug\
  IntermediateOutputPath: C:Debug\
Done Building Project "D:\Projects\Work\Repros\Test.proj" (default targets).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.63
Behaviour of Path.Join
D:\Projects\Work\Repros>dotnet msbuild Test.proj -p:Configuration=C:Debug -v:n

Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 18-07-2020 08:36:31 PM.
     1>Project "D:\Projects\Work\Repros\Test.proj" on node 1 (default targets).
     1>Test:
         MSBuildToolsVersion: Current
         MSBuildToolsPath:    C:\Program Files\dotnet\sdk\3.1.302
         MSBuildProjectDirectory: D:\Projects\Work\Repros
         BaseOutputPath: bin\
         BaseIntermediateOutputPath: obj\
         OutputPath: bin\C:Debug\
         IntermediateOutputPath: obj\C:Debug\
     1>Done Building Project "D:\Projects\Work\Repros\Test.proj" (default targets).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.21

Out of all the 3, which one do we want to have?

So far Path.Join is my favourite but it's not available to MSBuild for .NET Framework!

@rainersigwald
Copy link
Member

there's a noticeable difference of around 700ms-1s delay when using property functions

That's a shockingly large difference. Can you share exactly how you were testing?

Is there any guide/tool to properly profile MSBuild builds?

We have a fairly detailed evaluation-time profiler, and can also use our ETW events.

The NormalizeDirectory/NormalizePath doesn't always generate paths under MSBuildProjectDirectory. Is this Intentional?

The results you shared don't make any sense to me, no. Again, can you describe exactly how you got them?

@Nirmal4G
Copy link
Contributor Author

Nirmal4G commented Aug 5, 2020

Here's the test projects with different variations of OutputPath definitions: MSBuild-5238-Repro.zip

With both Desktop and Core MSBuild run the test projects with Configuration=C:Debug or PlatformName=C:ARM (i.e. prefix them with Windows Drive notation) and observe the differences.
They are of course invalid Configuration and Platform but Except /,\ and Path.Join all others have different behaviors with relative path inserted into the above properties.
I don't know what sort of problems they will bring down the road but I observed it by accident and so, I post here for clarification.

As you have suggested, we can also profile them with or without Common targets using ImportCommonTargets property. I will also profile them (both the test projects and PR patch) and post them here soon.

@Forgind
Copy link
Member

Forgind commented Aug 21, 2020

Without having looked too carefully, does this also resolve #2308?

@Nirmal4G
Copy link
Contributor Author

Nirmal4G commented Oct 13, 2020

@Forgind

Without having looked too carefully, does this also resolve #2308?

No, I don't think so. That requires changes in both C++ and .NET targets.

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

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

I need to look at the tests but other than the comments about "MPFProj" that I need clarification on this is looking good. Thanks for your patience!

src/Tasks/Microsoft.Common.CurrentVersion.targets Outdated Show resolved Hide resolved
While this is not officially supported on non-sdk projects,
 NuGet Pack targets need a common output path
 to put '.nupkg' across both type of projects
Replace 'HasTrailingSlash' conditional function with '[MSBuild]::EnsureTrailingSlash' property function
Replace '[System.IO.Path]::Combine' property function with '[MSBuild]::NormalizePath' and '[MSBuild]::NormalizeDirectory' property functions
when using OutputPath without BaseOutputPath
…bine paths

Usually, either '[MSBuild]::NormalizePath' or '[MSBuild]::NormalizeDirectory' property functions would be preferred for these cases.
But, there's a bug (on Windows) which occurs when a drive relative path like 'C:Projects' is specified and it fails to return to the project directory.

Usually, '[System.IO.Path]::Join' would be most preferred in this context. But, it's not available in NETFX. So, '[System.IO.Path]::Combine' is used instead.
Making sure that existing 'OutputPath' scenarios work, while allowing the use of 'BaseOutputPath' property
Adjust the wording to make it simple, brief and clear.

Co-Authored-By: Rainer Sigwald <raines@microsoft.com>

> Fixup with original commit when this patch is approved.
Silly ME!

There were a lot of build errors from the Fakes targets.
I was banging my head on which change caused this but finally found it.
Guess being sick has its perks.
Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@Nirmal4G
Copy link
Contributor Author

Nirmal4G commented Dec 2, 2020

@rainersigwald Sorry for the late reply!

Went to celebrate Diwali and came back with a bad case of cold.

Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for this!

Went to celebrate Diwali and came back with a bad case of cold.

I'm sorry to hear that. Glad you're feeling better!

@Nirmal4G
Copy link
Contributor Author

Nirmal4G commented Dec 5, 2020

I'm sorry to hear that. Glad you're feeling better!

I'm fine now. Thanks!

@Nirmal4G
Copy link
Contributor Author

Nirmal4G commented Dec 9, 2020

Finally! 🥳

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.

BaseOutputPath is not respected as per the documentation
4 participants