-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Conversation
Did you require any buildtools changes with this? do you mind sharing those if you did? |
src/Directory.Build.props
Outdated
<PropertyGroup> | ||
<EnableDefaultItems>false</EnableDefaultItems> | ||
<NoWarn>CS3021;$(NoWarn)</NoWarn> | ||
<RestoreOutputPath>$(MSBuildThisFileDirectory)\System.Runtime\ref\</RestoreOutputPath> |
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.
Why is this going to System.Runtime\ref?
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.
This is a remnant of changes I brought in from Jose's original changeset - the location pointed to here needs a project.assets.json file, which I also added in this change. I'm not married to that particular location
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.
This is wrong, I had it like this as part of my changes only when I was iterating on some changes and wanted to verify that stuff was being restored correctly. This should be removed.
src/Directory.Build.props
Outdated
<IsSDKProject>true</IsSDKProject> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<CSharpCoreTargetsPath>$(MSBuildExtensionsPath32)\Roslyn\Microsoft.CSharp.Core.targets</CSharpCoreTargetsPath> |
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.
Why do we need to explicitly set these here?
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.
This is also a remnant I took from Jose's original changeset - I haven't tried running a build without it yet.
src/Directory.Build.targets
Outdated
@@ -0,0 +1,14 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project InitialTargets="AddSkipGetTargetFrameworkToProjectReferences"> | |||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), dir.targets))\dir.targets" /> |
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.
What are these targets for?
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.
This is just what imports the parent directory's dir.targets. We used to have this per project, and we now have it only once on the common file.
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.
Should we instead of import dir.targets, rename dir.targets to Directory.Build.Targets?
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 be fine with that, though it would probably confuse some devs at first
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.
Directory.Build.Targets is a new feature of msbuild that some repos under dotnet/aspnet have started to use already:
https://github.com/search?q=org:dotnet+filename:directory.build.targets
https://github.com/search?q=org:aspnet+filename:directory.build.targets
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.
Do you think I should rename all dir.props/dir.targets to Directory.Build.props/targets? @joperezr is there documentation on how SDK projects automatically find files named as such? Will there be collisions if multiple files share that name across different parts of the directory tree?
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 documentation on how SDK projects automatically find files named as such?
Check out https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build
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.
dir.props and dir.targets are maltilayered in many repos (they are present at multiple directory levels and recursively each one includes higher level projects). Directory.Build.props/.targets are included once - after first include higher level ones will be skipped. This may cause some problems unless recursive include logic from dirs.props is applied to Directory.Build.* files as well.
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 expect we will recursively include them if we nest them.
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.
Yes, this is expected with Directory.Build.*. The first one gets imported, and then if there are parent props/targets files, they need to be explicitly included up the chain. This allows props/target authors to get the ordering right, which is important especially in props files.
We do this in the dotnet/machinelearning repo: https://github.com/dotnet/machinelearning/blob/master/src/Directory.Build.props#L3
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> | ||
<Project Sdk="Microsoft.NET.Sdk"> |
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.
@eerhardt are you aware of any way we can avoid setting this string in all our projects? We are very likely going to need to move to another SDK as part of our arcade repo and it would be great if we could just change it in one place in the repo if possible.
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.
Based on dotnet/msbuild#1493, we can use <Import>
semantics, because in Project Sdk="$(prop)"
, prop
does not be evaluated, nor in <Sdk Name="$(prop)">
. Alternatively, we can implement ISdkResolver
when it is implemented in MSBuild. :)
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.
You can do something like the following commit:
eerhardt/machinelearning@ed3c014
This allows my .csproj files to be built from the command line using dotnet build
.
However, VS 2017 throws an error trying to load this project:
---------------------------
Microsoft Visual Studio
---------------------------
Project file is incomplete. Expected imports are missing.
---------------------------
OK
---------------------------
@davkean - Any thoughts on this VS error?
@weshaggard - honestly, I think attempting to put the SDK name in a single place is going to be an uphill battle, and I'm not sure it is worth the effort. Yes, it will change one, maybe two more times. But IMO the work and effort of find/replace in a few hundred files is less than trying to do things that the tools weren't designed to support. And note that you need 2 imports in every .csproj with my approach above (props on top, targets on bottom).
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 agree it isn't a big deal. We should however be sure to keep the version out of all the project files as we we need to be able to override that in some cases like source-build so lets keep the version in the global.json file.
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.
The error above indicates that you are not importing Microsoft.Common.targets and indirectly Microsoft.Managed.DesignTime.targets. You can verify this by doing a msbuild /pp
on the project.
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.
You can import the SDK in a central props/targets, but then the central props/targets can't be Directory.Build.*
. Chicken and egg. Sdk imports common targets and common targets imports Directory.Build.*
If you use explicit dir.props/dir.targets, then you can do this: nguerrera/sdkimportrepro@6d34578
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 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.
nguerrera/sdkimportrepro@ab90e62 works fine in VS for me too. I cannot repro what @eerhardt is seeing with that approach.
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 tried it on today's daily dogfood build, and am no longer seeing the error. The project loads and builds correctly in VS.
I have not made any buildtools changes yet - the current state leaves me with the following error:
The fallback package folder location, |
Yes I would expect a buildtools change as well. |
src/Directory.Build.targets
Outdated
<Project InitialTargets="AddSkipGetTargetFrameworkToProjectReferences"> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), dir.targets))\dir.targets" /> | ||
<Target Name="_CheckForInvalidConfigurationAndPlatform" /> | ||
<Target Name="_CheckForUnsupportedTargetFramework" /> |
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.
Perhaps it is part of your buildtools changes but how are we blocking the import of the csharp targets?
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 haven't explicitly done this yet, maybe a change I will have to implement in buildtools.
Maybe because the project.assets.json path? |
To be honest, I don't remember entirely what that particular RestoreOutputPath was doing there, so I don't have a good answer to you. What I do know, is that the first project I converted and tried to get to compile succesfully was System.Runtime, which is probably related to the property. I would just remove it for now and try to build and see why/if it was needed. |
Updated to remove the project.assets.json file, now hitting the following error while running
|
Current state- With the above error, it appears the error is happening because we're running the target The only way to conditionally disable any of these targets is by setting As for |
@wtgodbe Do not set DesignTimeBuild to true. This is intended for VS purposes only. You should call Restore on the project - Restore is more than just packages, it's also contains information on indirect P2Ps which are promoted to real P2Ps in SDK-based projects. |
@wtgodbe I agree with @davkean that we shouldn't hack this and set DesignTimeBuild. @davkean for our corefx projects we have been disabling restore to avoid the extra cost for each project. We don't plan to use PackageReference's and there will be limited ProjectReferences in our repo, as we plan to override the target framework to reference a folder of refs that we build in our repo. Do you think the performance is good enough to try and enable restore for all our projects even though we expect it to be a no-op for almost all? Or should we try a disable restore in our common targets? |
Whether performance is good is the eye of the beholder; you should try using using implicit restore via MSBuild |
Thanks @davkean we definitely want to try and have consistency between command line and VS. We will try the default restore way first and measure before making a decision to disable it or not.
That isn't controllable via an msbuild property from the project? |
You can turn if via NuGet.config to prevent it from occurring automatically (say when you modify a project file or switch branches) and/or during build - but I see no reason why you would turn this on, unless it was causing issues, at which point we'd want bugs to fix said issues. Using Visual Studio is much nicer if you just let us do our thing to make the project in the state we think it should be. |
On this, by consistent behavior, I mean you might get different build errors based on whether you had previously restored using VS or not. For example, let's say you have A -> B -> C. For normal SDK-based projects, 'A' can use 'C'. If you turn off restore in command-line but not for VS - your going to different build error based on whether you've ever opened in VS or not. |
Probably we don't need to explicitly run " |
I agree for individual project builds we will just do dotnet build, but depending on the performance impact across the building of all projects we may do an upfront restore of all projects before we do a build, we will have to see the impact first. |
Never mind, I was building wrong. Build looks good in my (older) version of VS2017. I'm running a code coverage test run right now - it's taking a while, but seems to be working so far. |
I got the following test failures while running
I did get a coverage report, though. I'll compare that to the result of just running build-test to see if the errors are specific to the coverage run. |
This is what I get running a normal test build:
|
I'm removing the WIP on this PR. I believe this is ready for review and to be merged. All the legs should be passing - I will fix them if they aren't.
@weshaggard @wtgodbe - please take a look. Since this change is so big, it will probably be easiest to review this change commit-by-commit, and possibly skipping the merge commits. Unless you want to pull the change locally and review it that way. |
<!-- Set up default paths for reference assemblies --> | ||
<PropertyGroup Condition="'$(IsReferenceAssembly)'=='true'"> | ||
<!-- Create a common root output directory for all reference assemblies --> | ||
<ReferenceAssemblyOutputPath Condition="'$(ReferenceAssemblyOutputPath)' == ''">$(BaseOutputPath)ref/</ReferenceAssemblyOutputPath> |
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.
Why did these get moved here instead of using the ones in BuildTools? https://github.com/dotnet/buildtools/blob/16a6d1f39cf0a572041d51bd318913548ba41b34/src/Microsoft.DotNet.Build.Tasks/PackageFiles/ReferenceAssemblies.targets#L15
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 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'd like to understand if it is needed here still.
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've investigated why this was being set.
The reason looks to be that the BuildTools setting of $(OutputPath)
is now occurring too late in the project evaluation. Before SDK-style projects, BuildTools' ReferenceAssemblies.targets
is imported before Microsoft.Common.targets
. Now, with SDK-style projects, ReferenceAssemblies.targets
is being imported after Microsoft.Common.targets
.
This change was attempting to set these properties earlier, but aren't the real fix since $(AssemblyVersion)
is not set yet. To fix this, I opened a BuildTools PR: dotnet/buildtools#2091. After we take that fix into corefx, we can remove this section and use the ones in BuildTools.
@@ -5,7 +5,7 @@ | |||
<ProjectGuid>{3CA89D6C-F8D1-4813-9775-F8D249686E31}</ProjectGuid> | |||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |||
<ILLinkClearInitLocals>true</ILLinkClearInitLocals> | |||
<Configurations>netcoreapp-Linux-Debug;netcoreapp-Linux-Release;netcoreapp-OSX-Debug;netcoreapp-OSX-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release</Configurations> | |||
<Configurations>netcoreapp-Linux-Debug;netcoreapp-Linux-Release;netcoreapp-OSX-Debug;netcoreapp-OSX-Release;netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release</Configurations> |
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.
Do you know if these have to be static and directly in the project? I'm asking mainly to try and determine if we can combine the Debug/Release aspects with our existing BuildConfigurations property to eliminate the duplication.
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 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 believe it has to be known at evaluation time (i.e. Not the result of a target), but doesn't have to be directly in the project. @davkean would know for sure.
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.
Looks good overall. Thanks for pushing this through.
We probably need to go and update some documentation around how to build and edit projects. Can you please take a pass through and make some updates?
@dotnet-bot test this please |
@dotnet-bot test this please |
Test Windows x64 Debug Build |
1 similar comment
Test Windows x64 Debug Build |
Convert all projects to SDK-style Commit migrated from dotnet/corefx@0b0f63d
Part of https://github.com/dotnet/corefx/projects/3
CC @weshaggard @joperezr @safern @eerhardt