cake-contrib / Cake_Git

Cake AddIn that extends Cake with Git features using LibGit2 and LibGit2Sharp
https://cakebuild.net/extensions/cake-git
Other
39 stars 63 forks source link

Simple way of getting location of devenv.exe #162

Closed tapika closed 2 years ago

tapika commented 2 years ago

I wanted to build with cake filtered solution - *.slnf.

https://docs.microsoft.com/en-us/visualstudio/ide/filtered-solutions?view=vs-2019

And I think it's not possible to be done with msbuild.exe - I've tried to switch from msbuild.exe to devenv.exe.

And in order to do that one - I needed to know location of devenv.exe - and checked that there exists functions which can be used, but they are quite hidden one.

I wrote something like this:

Type t = typeof(MSBuildSettings).Assembly.GetType("Cake.Common.Tools.MSBuild.MSBuildResolver");
var m = t.GetMethod("GetMSBuildPath", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);

FilePath msbuildExePath = (FilePath)m.Invoke(null, new object[] { new FileSystem(), 
    new CakeEnvironment(new CakePlatform(), new CakeRuntime()), MSBuildToolVersion.VS2017, MSBuildPlatform.x64, null });
string dir = new FileInfo(msbuildExePath.FullPath).Directory.Parent.Parent.Parent.Parent.FullName;
string devenvPath = Path.Combine(dir, @"Common7\IDE\devenv.exe");

But would it be possible to simplify this - maybe making specific methods public ?

tapika commented 2 years ago

Just to be fully strict - apparently filtered solutions are not supported by vs2017 toolset - but they are supported by vs2019 - so theoretically replacing MSBuildToolVersion.VS2017 to MSBuildToolVersion.VS2019 should fix the issue.

However - while testing how msbuild.exe works comparing to devenv.com (That's right - I had also extension incorrect) - I've noticed that msbuild.exe fails where devenv.com works out of box.

We have special native C++ nuget package included into project (microsoft.dxsdk.d3dx) and for some reason C++ cannot find right include folders, which in a turn manifests as an error.

fatal error C1083: Cannot open include file: 'd3dx9tex.h': No such file or directory

Would be interesting to find out root cause of that, but this does not relate to this ticket itself.

I think building using devenv.com should be supported as well as building via msbuild.exe.

nils-a commented 2 years ago

Hi @tapika cake.git is about using git in Cake. For your questions, I suggest opening a discussion in the Cake project and see if someone there might be able to help.

(In your case, I would suggest having a look at the vswhere-tool in combination with the Cake vswhere aliases.)

tapika commented 2 years ago

My assumption was that I type <component> git and will end up into correct git repository. Sorry, my mistake. :-)

Opened as discussion in here: https://github.com/cake-build/cake/discussions/3889