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

Document how to resolve MSBuild location #1377

Closed
devlead opened this issue Nov 22, 2016 · 15 comments
Closed

Document how to resolve MSBuild location #1377

devlead opened this issue Nov 22, 2016 · 15 comments
Assignees
Labels
Documentation Issues about docs, including errors and areas we should extend (this repo and learn.microsoft.com) triaged
Milestone

Comments

@devlead
Copy link
Contributor

devlead commented Nov 22, 2016

Following up twitter discussion with @terrajobst and @damianh and creating this issue to track progress of the docs being created.

@terrajobst wrote:
I've pinged the MSBuild folks. They are working on a doc that will be public soon.

@devlead wrote:
@terrajobst @RandomPunter that's great news! Thanks for getting back to us, is there an GH issue one can subscribe to?

@terrajobst wrote:
@devlead @RandomPunter no, but feel free to create one. I'll let them know that they should respond to it. https://GitHub.com/Microsoft/MSBuild/issues/new

Full thread here

Not certain on what's exactly being documented, but I guess if we find anything lacking we'll post that feedback here.

@Sarabeth-Jaffe-Microsoft Sarabeth-Jaffe-Microsoft added the Documentation Issues about docs, including errors and areas we should extend (this repo and learn.microsoft.com) label Nov 22, 2016
@Sarabeth-Jaffe-Microsoft
Copy link
Contributor

Sarabeth-Jaffe-Microsoft commented Nov 22, 2016

Thanks for creating this issue, @devlead. Documentation is currently in the works. Feel free to ask questions regarding the VS 2017 RC release here.

@jnm2
Copy link

jnm2 commented Dec 17, 2016

If I have an open source project with a build script, my build script should not have to be responsible to decide what edition of Visual Studio is preferred when locating msbuild if there are multiple installed (Community vs Professional trial).

Ideally there should be a way to locate the default msbuild path for a given tool version.

@devlead
Copy link
Contributor Author

devlead commented Dec 17, 2016

Well the author of a build script should be able to pin which version of the tooling to use, for that to work we either need reliable documented way to find and execute that version. Or be able to fetch that tool via i.e. something like NuGet or Chocolatey.

@jnm2
Copy link

jnm2 commented Dec 17, 2016

Fetching msbuild via a NuGet feed would be fantastic. I wouldn't have to worry what was installed and I'd have fine-grained control over minimum and maximum versions.

@jnm2
Copy link

jnm2 commented Dec 17, 2016

What I strongly dislike is this fragility:

var msbuildPath = Path.Combine(
    Directory.EnumerateDirectories(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft Visual Studio", "2017")).First(),
    "MSBuild", "15.0", "Bin", "msbuild.exe");

Not only do I want to use msbuild if VS is not installed, but I also don't want to have to search a cross product of VS versions, VS editions, and msbuild versions.

@devlead
Copy link
Contributor Author

devlead commented Dec 17, 2016

Bootstrapping from NuGet also makes allot of sense for build agent scenarios.
Still waiting see what the end result of project.json->csproj will be, but if the tooling is a first class citizen then all non standard msbuild targets should be able to be fetched thru NuGet too.
Which feels almost utopian when I think of it 😄

@damianh
Copy link

damianh commented Dec 17, 2016 via email

@jnm2
Copy link

jnm2 commented Dec 17, 2016

Is it safe to start a request specifically for a NuGet tools package?

Otherwise we're stuck in a world I really don't want to live in:

string GetMSBuildPath(Version minVersion, Version maxVersion)
{
    if (minVersion < new Version(15, 0))
        throw new NotImplementedException("Logic for pre-15.0 msbuild location");

    return (
        from vsVersionDir in Directory.EnumerateDirectories(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft Visual Studio"))
        let vsVersion = int.TryParse(Path.GetFileName(vsVersionDir), out int version) ? version : (int?)null
        where vsVersion != null
        orderby vsVersion descending
        from vsEditionDir in Directory.EnumerateDirectories(vsVersionDir)
        // orderby ?
        from msbuildVersionDir in Directory.EnumerateDirectories(Path.Combine(vsEditionDir, "MSBuild"))
        let msbuildVersion = Version.TryParse(Path.GetFileName(msbuildVersionDir), out Version version) ? version : null
        where msbuildVersion != null && (minVersion == null || minVersion <= msbuildVersion) && (maxVersion == null || msbuildVersion <= maxVersion)
        orderby msbuildVersion descending
        let msbuildPath = Path.Combine(msbuildVersionDir, "Bin", "msbuild.exe")
        where File.Exists(msbuildPath)
        select msbuildPath).FirstOrDefault();
}

@clairernovotny
Copy link
Member

One thing I've noticed is that there is a difference between which MSBuild version is used and the things like MSBuildExtensions directory. If you're just doing vanilla builds, this doesn't matter. But if you're using multi-targeting to include the "native platform" targets like the WindowsXaml one, where it needs to be the version of MSBuild set by "VCVars" so that it picks up all those paths correctly.

Either that or ship all of the platform tasks/targets as NuGet's (even if they will only run on Windows).

@clairernovotny
Copy link
Member

Bottom line -- if you want to use the native platform targets, it will require VS on the machine and knowing to use the version of MSBuild from that particular instance. 

@devlead
Copy link
Contributor Author

devlead commented Dec 17, 2016

Bottom line -- if you want to use the native platform targets, it will require VS on the machine and knowing to use the version of MSBuild from that particular instance. 

Even if this is the case today I don't think it should be tomorrow, SDKs shouldn't be tied to specific IDE version just to be able to build it. Anyone that's done CI with Silverlight, older versions of MVC, SQL Assemblies, etc. etc. can attest how horrible that experience can be. And hopefully we're better than that 2016.
Having to install & maintain all ever created versions of Visual Studio just doesn't fly. But is a must as they drop support for as many project types as they add each version.

Having the possibility to fetch and use a specific version tooling was one of the most appealing features of .NET Core, one would hope that's a behavior getting more adopted by more SDKs and tools going forward.

@clairernovotny
Copy link
Member

clairernovotny commented Dec 17, 2016

@devlead Oh, I agree. I'd love to have all of the platform-specific targets/tasks be available via NuGet. Just saying that they're not today and that the location of msbuild matters :/

@devlead
Copy link
Contributor Author

devlead commented Dec 17, 2016

@onovotny that's why I'm looking forward to at least having good and clear documentation on how to find specific installed versions of MSBuild.

@rainersigwald
Copy link
Member

The VS setup team has posted a PowerShell helper to find Visual Studio installs: https://github.com/Microsoft/vssetup.powershell/wiki.

MSBuild should be present in every install of VS2017 (that I know of). But the tasks, targets, and other extensions required to build a specific project may not be available in every instance. To be fully robust, you probably want to query for a specific workload/component corresponding to your project type (for example, you might know that you need Microsoft.VisualStudio.WCF).

@Sarabeth-Jaffe-Microsoft we need to make sure this makes it into formal documentation.

@rainersigwald
Copy link
Member

MicrosoftDocs/visualstudio-docs#761 has documentation on how to use Microsoft.Build.Locator to load the copy of MSBuild from the user's installed Visual Studio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues about docs, including errors and areas we should extend (this repo and learn.microsoft.com) triaged
Projects
None yet
Development

No branches or pull requests

7 participants