-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MSBuild 15 Sdk Design #1493
Comments
How does this play with VS Code, JetBrains Rider, Xamarin, MonoDevelop, ...? |
@jviau We're designing a way for a UI to provide to MSBuild some logic that resolves an SDK. The implication for VS is that it would want to present the user with a progress dialog while it restores packages during project load. Our design here means that VS would specify a class to MSBuild that we would create an instance of and call |
We have items near the bottom to involve VS Code, VS Mac and dotnet CLI to ensure they can pass a resolver to give the user a good experience. JetBrains Rider and MonoDevelop will need to implement the interface for displaying a progress dialog to the user. I'm fairly certain they already have a custom MSBuild logger to handle log output like Visual Studio so we're hoping it will be easy for IDEs to make this happen for the SDK resolution. We can probably pave the way with the ones we ship in VS that they can re-use or take as an example. |
@AndyGerlicher What do you think about making this more generic and extensible? Right now it's specifically for resolving SDKs but do you think we'll ever want to resolve other project assets? My thought was to have the logic be more centered around resolving assets, one of which would be an SDK. Something like: public interface AssetResolver
{
IEnumerable<IResolvedAsset> Resolve(IEnumerable<IAsset> assets);
}
public enum AssetType
{
None,
SDK,
}
public interface IAsset
{
AssetType AssetType { get; }
string Name { get; }
Version Version { get; }
}
public interface IResolvedAsset : IAsset
{
/// <summary>
/// The path to the resolved asset.
/// </summary>
string Path { get; }
} Thoughts? |
I also looked at logging and it's going to be tricky. The only thing available during project evaluation is the internal LoggingService so we'd need a new interface to expose to the caller or allow them to throw exceptions. If we want them to be able to log messages and warnings we'll need to come up with something. |
This sounds like a very intriguing and valuable feature!
Please consider making this an XML file, to keep it consistent with the current ecosystem. It would be confusing to introduce differing and inconsistent data formats, especially after moving from XML to JSON and then back to XML again. The spirit of the request here isn't to favor a particular format, but rather to favor consistency. I might be alone on this, however. But to me, exploring a given a solution (VS or otherwise) and seeing two different data files in two different formats when they both simply describe data is not only maddeningly inconsistent, but inefficient as well. That means you ultimately have two libraries/concerns in your solution that parse/save data, when it could be done with just one. Of course, if you provide a strictly POCO-based model whereby the end user could describe their data in the format they prefer, then this is a non-issue. 😄 What strikes me about this feature is that the same sort of magic could eventually be used to download/install data-format preferences/serialization components as well -- something that has been discussed in #613. |
@jeffki Is he resolver ever an IDE-specific extension or is the IDE's only role to call into msbuild and show progress? |
@jeffkl I am a bit confused by the VS UI interaction. Is VS supposed to implement its own |
@jviau Yes Visual Studio's implementation of |
@maartenba The IDE will new up a |
@jeffkl will this be a VS-wide implementation, or is it provided per |
@jeffki so looking at the various responses the IDE would be responsible for ánd logging ánd resolving SDK's? Does that also imply a build server should perform both these tasks? |
@jviau We think resolvers would be like loggers so they would have a wide scope like MSBuild will be passed an instance of the resolver and call it to resolve any unresolved SDKs. So yes CPS would construct it. |
@maartenba For command-line based builds, MSBuild will ship with a resolver that logs to the console. So build servers will not need any resolvers. The main issue is that UI applications would want to pop up their customer dialogs and may have their own way of acquiring SDKs. |
@jeffkl I'm concerned that IDE will be able to handle SDK resolving. That way MSBuild will have a different behaviour depending on environment it was started in. It may lead to subtle differences between builds inside IDE and on a build server. |
@shalupov I'll update the design to note that although different resolvers could run, the full closure of what they resolve would be identical. In the case of an SDK, it's just a NuGet package so when building from the command-line the same NuGet package would be used as the one when building from an IDE. The differences would be in how the end-user application acquires the package (uses its own copy of NuGet, downloads NuGet, uses just the web protocols to get the file) and how it presents progress (a progress dialog or logging to the console). |
@AndyGerlicher can you explain how these files are different than using a Or are lineups only for managing |
Will this changes allso apply to c++ project? |
From API perspective, you shouldn't be returning a concrete |
Just putting forth an idea for the "lineup" mechanism. You could make projects in a solution share the same lineup perhaps using the SDK attribute: Project A:
Project B:
Then in a well known directory, relative to the project / solution dir, you'd have a matching This could use the explicit or implicit form:
This would act as the lineup file, i.e you can manage sdk version in one place. If msbuild couldn't find a matching targets file, then it could just attempt to resolve the SDK using normal resolution. If you needed to special case some projects in your giant solution, to use a different version of some of the SDK's, for those projects you could:
And then you add
|
@dazinator wouldn't that be exactly the same as the |
* Adds support for MSBuild to discover plug-in based resolvers for the 'SDK' import feature. A resolver assembly can be placed in: MSBuild\SdkResolver\(ResolverName)\(ResolverName).dll MSBuild will create an instance of any class that implements SdkResolver and attempt to resolve all SDK references with those resolver (sorted by SdkResolver.Priority). * Adds support for MSBuild to consume an Sdk reference as element (as an alternative to a property on the Project element). Both versions of the syntax will add an implicit Import element at the top and the bottom of the file. Related to dotnet#1493
* Adds support for MSBuild to discover plug-in based resolvers for the 'SDK' import feature. A resolver assembly can be placed in: MSBuild\SdkResolver\(ResolverName)\(ResolverName).dll MSBuild will create an instance of any class that implements SdkResolver and attempt to resolve all SDK references with those resolver (sorted by SdkResolver.Priority). * Adds support for MSBuild to consume an Sdk reference as element (as an alternative to a property on the Project element). Both versions of the syntax will add an implicit Import element at the top and the bottom of the file. Related to dotnet#1493
* Adds support for MSBuild to discover plug-in based resolvers for the 'SDK' import feature. A resolver assembly can be placed in: MSBuild\SdkResolver\(ResolverName)\(ResolverName).dll MSBuild will create an instance of any class that implements SdkResolver and attempt to resolve all SDK references with those resolver (sorted by SdkResolver.Priority). * Adds support for MSBuild to consume an Sdk reference as element (as an alternative to a property on the Project element). Both versions of the syntax will add an implicit Import element at the top and the bottom of the file. Related to #1493
Note on lineups: in addition to version unification, it might be helpful/required to be able to specify what resolver should be used to resolve a specified SDK. |
Is it still supposed to keep ability to extend MSBuild process using properties like
However any changes in the property group didn't make any difference |
@mkarpuk Physically where in the project file did you define that property? The defaults are set in Is there a reason you don't want to inject your property using <Target Name="EmitMessageBeforeResolveReferences"
BeforeTargets="ResolveReferences">
<Message Text="It Works!" Importance="high"/>
</Target>
And then it could be defined anywhere in the file. |
I put |
@rainersigwald I'd like to start using custom SDKs in our repos. Is there a spec (or a sample) I can look at to see how this works end-to-end (covering lineups etc.)? |
I agree, its time to put a "fork" in this one |
@tmat please see https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/msbuild/how-to-use-project-sdk.md for some documentation, feedback welcome! |
@jeffkl Thanks! This feature has a potential to significantly simplify our repos. Looking forward testing it out. |
MSBuild will allow third-party-defined and dynamically-delivered extensions of the build process via the new “Sdk” concept. This will extend the experience delivered with RC.2 to include an acquisition process.
Changes to project files
An Sdk can be consumed in two ways: with implicit top and bottom imports at through the
Sdk
attribute on theProject
element:and through a modified
<Import>
element with theSdk
attribute:The former mechanism is syntactic sugar for the latter, with an
Sdk.props
import at the top of the project and anSdk.targets
import at its bottom.User experience
When a user opens an Sdk-using project in an IDE, the IDE will try to evaluate the project. MSBuild will coordinate with the IDE to fetch and integrate all required Sdks. The IDE will probably wish to display a progress bar for any required downloads.
On the command line, a
dotnet restore
ormsbuild.exe /t:Restore
invocation will fetch required Sdks before proceeding with the restore process, ensuring that only one user gesture is required to bring the project to a buildable state.Sdk acquisition
How does MSBuild know how to acquire an Sdk when it needs to? Through a provider model. A caller of the MSBuild APIs can provide an instance of a new interface
ISdkResolver
which will be used to map the XML from above to files on the local filesystem.Note: Although the acquisition could differ between builds the resolved SDK would be identical.
We expect most
ISdkResolver
implementations to additionally have affordances for reporting progress back to a UI and to log using the MSBuild log interface.🚧 Exposing logging may require an interface change here.
🚧 Do we need to pass path-to-project, so that something NuGet-like can walk up to find its feed configuration?
MSBuild evaluation changes
MSBuild will collect Sdks needed for a given project early in its evaluation (before pass 1 expands imports). It will then unify Sdks specified within the project with those specified in the (optional) lineup file. This produces a list of Sdks that is then passed to
ISdkResolver.Resolve()
, producing a lookup table for Sdk imports.Evaluator.GetCurrentDirectoryForConditionEvaluation
should return the Sdk directory if there is anSdk
attribute on an import, so that you can have something likeCondition="Exists('Sdk\Sdk.props')"
on an Sdk import.Evaluation pass 1 (properties and imports) then continues as usual. When considering an
Import
element with anSdk
attribute, the specifiedProject
attribute is treated as a relative path from the base Sdk path looked up in the table generated in the new pre-pass-1 step.Lineups
After growing past being “small” projects, most repos/solutions will want a simple way to manage the set of Sdks they use--for instance, to unify versions of Sdks available for projects within the repo. This will be accomplished by a lineup file, format TBD, that MSBuild will consider when putting together the list of available Sdks.
🚧 What does this look like on disk?
We expect a few common patterns of use:
Project Load
We'll need to add to ProjectLoadSettings so a user can opt out of SDK resolution. They would need to specify both
IgnoreMissingImports
and a newDoNotResolveSdks
if they wanted to open a project without getting errors. But this would allow minimal property evaluation without resolving anything.Concrete work items
ISdkResolver
definition for prototyping.ISdkResolver
BuildParameters
?BuildRequestData
?FilesystemSdkResolver
for prototyping and testingNuGetSdkResolver
: Proposal: implement a SdkResolver for NuGet packages NuGet/Home#5220dotnet
CLI to invoke MSBuild with a resolverThe text was updated successfully, but these errors were encountered: