Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5fa399e

Browse files
authored
Fixes #1559 --- Ensure that Legacy Project System Consistently sets SolutionDir etc .... (#4419)
* issue 1559* passes* feedback* RoslynPackageVersion.txt
1 parent6329b76 commit5fa399e

File tree

6 files changed

+176
-39
lines changed

6 files changed

+176
-39
lines changed

‎RoslynPackageVersion.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.8.2
1+
2.8.0

‎vsintegration/src/FSharp.ProjectSystem.Base/Project/ProjectFactory.cs‎

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ namespace Microsoft.VisualStudio.FSharp.ProjectSystem
2222
internalabstractclassProjectFactory:Microsoft.VisualStudio.Shell.Flavor.FlavoredProjectFactoryBase
2323
,IVsProjectUpgradeViaFactory,IVsProjectUpgradeViaFactory4
2424

25-
{
26-
privateMicrosoft.VisualStudio.Shell.Packagepackage;
27-
privateSystem.IServiceProvidersite;
25+
{
26+
privateMicrosoft.VisualStudio.Shell.Packagepackage;
27+
privateSystem.IServiceProvidersite;
2828

2929
privateMicrosoft.Build.Evaluation.ProjectCollectionbuildEngine;
3030
privateMicrosoft.Build.Evaluation.ProjectbuildProject;
@@ -112,14 +112,56 @@ protected override void CreateProject(string fileName, string location, string n
112112
}
113113
}
114114

115+
// Solution properties
116+
IVsSolutionsolution=this.Site.GetService(typeof(SVsSolution))asIVsSolution;
117+
Debug.Assert(solution!=null,"Could not retrieve the solution service from the global service provider");
118+
119+
// We do not want to throw. If we cannot set the solution related constants we set them to empty string.
120+
stringsolutionDirectory,solutionPath,userOptionsFile;
121+
solution.GetSolutionInfo(outsolutionDirectory,outsolutionPath,outuserOptionsFile);
122+
if(solutionDirectory==null)
123+
{
124+
solutionDirectory=String.Empty;
125+
}
126+
if(solutionPath==null)
127+
{
128+
solutionPath=String.Empty;
129+
}
130+
stringsolutionFileName=(solutionPath.Length==0)?String.Empty:Path.GetFileName(solutionPath);
131+
stringsolutionName=(solutionPath.Length==0)?String.Empty:Path.GetFileNameWithoutExtension(solutionPath);
132+
varsolutionExtension=Path.GetExtension(solutionPath);
133+
134+
// DevEnvDir property
135+
IVsShellshell=this.Site.GetService(typeof(SVsShell))asIVsShell;
136+
Debug.Assert(shell!=null,"Could not retrieve the IVsShell service from the global service provider");
137+
objectinstallDirAsObject;
138+
139+
// We do not want to throw. If we cannot set the solution related constants we set them to empty string.
140+
shell.GetProperty((int)__VSSPROPID.VSSPROPID_InstallDirectory,outinstallDirAsObject);
141+
stringinstallDir=((string)installDirAsObject);
142+
if(String.IsNullOrEmpty(installDir))
143+
{
144+
installDir=String.Empty;
145+
}
146+
else
147+
{
148+
// Ensure that we have trailing backslash as this is done for the langproj macros too.
149+
if(installDir[installDir.Length-1]!=Path.DirectorySeparatorChar)
150+
{
151+
installDir+=Path.DirectorySeparatorChar;
152+
}
153+
}
154+
115155
// Get the list of GUIDs from the project/template
116156
stringguidsList=this.ProjectTypeGuids(fileName);
117157

118158
// Launch the aggregate creation process (we should be called back on our IVsAggregatableProjectFactoryCorrected implementation)
119159
IVsCreateAggregateProjectaggregateProjectFactory=(IVsCreateAggregateProject)this.Site.GetService(typeof(SVsCreateAggregateProject));
120160
inthr=aggregateProjectFactory.CreateAggregateProject(guidsList,fileName,location,name,flags,refprojectGuid,outproject);
121161
if(hr==VSConstants.E_ABORT)
162+
{
122163
canceled=1;
164+
}
123165
ErrorHandler.ThrowOnFailure(hr);
124166

125167
this.buildProject=null;
@@ -146,6 +188,67 @@ protected override object PreCreateForOuter(IntPtr outerProjectIUnknown)
146188
returnnode;
147189
}
148190

191+
internalMicrosoft.Build.Evaluation.ProjectReinitializeMsBuildProject(stringfilename)
192+
{
193+
// Solution properties
194+
IVsSolutionsolution=this.Site.GetService(typeof(SVsSolution))asIVsSolution;
195+
Debug.Assert(solution!=null,"Could not retrieve the solution service from the global service provider");
196+
197+
// We do not want to throw.If we cannot set the solution related constants we set them to empty string.
198+
stringsolutionDirectory,solutionPath,userOptionsFile;
199+
solution.GetSolutionInfo(outsolutionDirectory,outsolutionPath,outuserOptionsFile);
200+
if(solutionDirectory==null)
201+
{
202+
solutionDirectory=String.Empty;
203+
}
204+
if(solutionPath==null)
205+
{
206+
solutionPath=String.Empty;
207+
}
208+
stringsolutionFileName=(solutionPath.Length==0)?String.Empty:Path.GetFileName(solutionPath);
209+
stringsolutionName=(solutionPath.Length==0)?String.Empty:Path.GetFileNameWithoutExtension(solutionPath);
210+
stringsolutionExtension=String.Empty;
211+
if(solutionPath.Length>0&&Path.HasExtension(solutionPath))
212+
{
213+
solutionExtension=Path.GetExtension(solutionPath);
214+
}
215+
216+
//DevEnvDir property
217+
IVsShellshell=this.Site.GetService(typeof(SVsShell))asIVsShell;
218+
Debug.Assert(shell!=null,"Could not retrieve the IVsShell service from the global service provider");
219+
objectinstallDirAsObject;
220+
221+
//We do not want to throw.If we cannot set the solution related constants we set them to empty string.
222+
shell.GetProperty((int)__VSSPROPID.VSSPROPID_InstallDirectory,outinstallDirAsObject);
223+
stringinstallDir=((string)installDirAsObject);
224+
if(String.IsNullOrEmpty(installDir))
225+
{
226+
installDir=String.Empty;
227+
}
228+
else
229+
{
230+
//Ensure that we have trailing backslash as this is done for the langproj macros too.
231+
if(installDir[installDir.Length-1]!=Path.DirectorySeparatorChar)
232+
{
233+
installDir+=Path.DirectorySeparatorChar;
234+
}
235+
}
236+
237+
varprojectGlobalPropertiesThatAllProjectSystemsMustSet=newDictionary<string,string>()
238+
{
239+
{GlobalProperty.SolutionDir.ToString(),solutionDirectory},
240+
{GlobalProperty.SolutionPath.ToString(),solutionPath},
241+
{GlobalProperty.SolutionFileName.ToString(),solutionFileName},
242+
{GlobalProperty.SolutionName.ToString(),solutionName},
243+
{GlobalProperty.SolutionExt.ToString(),solutionExtension},
244+
{GlobalProperty.BuildingInsideVisualStudio.ToString(),"true"},
245+
{GlobalProperty.Configuration.ToString(),""},
246+
{GlobalProperty.Platform.ToString(),""},
247+
{GlobalProperty.DevEnvDir.ToString(),installDir}
248+
};
249+
returnUtilities.ReinitializeMsBuildProject(this.buildEngine,filename,projectGlobalPropertiesThatAllProjectSystemsMustSet,this.buildProject);
250+
}
251+
149252
/// <summary>
150253
/// Retrives the list of project guids from the project file.
151254
/// If you don't want your project to be flavorable, override
@@ -158,7 +261,7 @@ protected override string ProjectTypeGuids(string file)
158261
{
159262
// Load the project so we can extract the list of GUIDs
160263

161-
this.buildProject=Utilities.ReinitializeMsBuildProject(this.buildEngine,file,this.buildProject);
264+
this.buildProject=this.ReinitializeMsBuildProject(file);
162265

163266
// Retrieve the list of GUIDs, if it is not specify, make it our GUID
164267
stringguids=buildProject.GetPropertyValue(ProjectFileConstants.ProjectTypeGuids);
@@ -168,7 +271,6 @@ protected override string ProjectTypeGuids(string file)
168271
returnguids;
169272
}
170273

171-
172274
privateclassProjectInspector
173275
{
174276
privateMicrosoft.Build.Construction.ProjectRootElementxmlProj;

‎vsintegration/src/FSharp.ProjectSystem.Base/Project/ProjectNode.cs‎

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,10 @@ public enum EventTriggering
589589
/// </summary>
590590
privateDictionary<Type,Guid>catidMapping=newDictionary<Type,Guid>();
591591

592-
/// <summary>
593-
/// The public package implementation.
594-
/// </summary>
595-
privateProjectPackagepackage;
592+
/// <summary>
593+
/// The public package implementation.
594+
/// </summary>
595+
privateProjectPackagepackage;
596596

597597
privateboolisDisposed;
598598

@@ -1945,17 +1945,17 @@ public virtual void Load(string fileName, string location, string name, uint fla
19451945
this.ProjectMgr=this;
19461946
this.isNewProject=false;
19471947

1948-
if((flags&(uint)__VSCREATEPROJFLAGS.CPF_CLONEFILE)==(uint)__VSCREATEPROJFLAGS.CPF_CLONEFILE)
1949-
{
1950-
// we need to generate a new guid for the project
1951-
this.projectIdGuid=Guid.NewGuid();
1952-
}
1953-
else
1954-
{
1955-
this.SetProjectGuidFromProjectFile(false);
1956-
}
1948+
if((flags&(uint)__VSCREATEPROJFLAGS.CPF_CLONEFILE)==(uint)__VSCREATEPROJFLAGS.CPF_CLONEFILE)
1949+
{
1950+
// we need to generate a new guid for the project
1951+
this.projectIdGuid=Guid.NewGuid();
1952+
}
1953+
else
1954+
{
1955+
this.SetProjectGuidFromProjectFile(false);
1956+
}
19571957

1958-
this.buildEngine=Utilities.InitializeMsBuildEngine(this.buildEngine);
1958+
this.buildEngine=Utilities.InitializeMsBuildEngine(this.buildEngine);
19591959

19601960
// based on the passed in flags, this either reloads/loads a project, or tries to create a new one
19611961
// now we create a new project... we do that by loading the template and then saving under a new name
@@ -1967,7 +1967,7 @@ public virtual void Load(string fileName, string location, string name, uint fla
19671967
this.isNewProject=true;
19681968

19691969
// This should be a very fast operation if the build project is already initialized by the Factory.
1970-
SetBuildProject(Utilities.ReinitializeMsBuildProject(this.buildEngine,fileName,this.buildProject));
1970+
SetBuildProject(Utilities.ReinitializeMsBuildProject(this.buildEngine,fileName,this.ProjectGlobalPropertiesThatAllProjectSystemsMustSet,this.buildProject));
19711971

19721972

19731973
// Compute the file name
@@ -2876,7 +2876,7 @@ public virtual void Reload()
28762876
this.isClosed=false;
28772877
this.eventTriggeringFlag=ProjectNode.EventTriggering.DoNotTriggerHierarchyEvents|ProjectNode.EventTriggering.DoNotTriggerTrackerEvents;
28782878

2879-
SetBuildProject(Utilities.ReinitializeMsBuildProject(this.buildEngine,this.filename,this.buildProject));
2879+
SetBuildProject(Utilities.ReinitializeMsBuildProject(this.buildEngine,this.filename,this.ProjectGlobalPropertiesThatAllProjectSystemsMustSet,this.buildProject));
28802880

28812881
// Load the guid
28822882
this.SetProjectGuidFromProjectFile(true);
@@ -3099,45 +3099,47 @@ internal virtual BuildResult InvokeMsBuild(string target, IEnumerable<KeyValuePa
30993099
}
31003100
}
31013101

3102+
internalIDictionary<string,string>ProjectGlobalPropertiesThatAllProjectSystemsMustSet{get;set;}
3103+
31023104
voidSetupProjectGlobalPropertiesThatAllProjectSystemsMustSet()
31033105
{
31043106
// Much of the code for this method is stolen from GlobalPropertyHandler.cs. That file is dev-9 only;
31053107
// whereas this code is for dev10 and specific to the actual contract for project systems in dev10.
31063108
UIThread.MustBeCalledFromUIThread();
3107-
3109+
31083110
// Solution properties
31093111
IVsSolutionsolution=this.Site.GetService(typeof(SVsSolution))asIVsSolution;
31103112
Debug.Assert(solution!=null,"Could not retrieve the solution service from the global service provider");
31113113

3112-
stringsolutionDirectory,solutionFile,userOptionsFile;
3114+
stringsolutionDirectory,solutionPath,userOptionsFile;
31133115

31143116
// We do not want to throw. If we cannot set the solution related constants we set them to empty string.
3115-
solution.GetSolutionInfo(outsolutionDirectory,outsolutionFile,outuserOptionsFile);
3117+
solution.GetSolutionInfo(outsolutionDirectory,outsolutionPath,outuserOptionsFile);
31163118

31173119
if(solutionDirectory==null)
31183120
{
31193121
solutionDirectory=String.Empty;
31203122
}
31213123

31223124

3123-
if(solutionFile==null)
3125+
if(solutionPath==null)
31243126
{
3125-
solutionFile=String.Empty;
3127+
solutionPath=String.Empty;
31263128
}
31273129

31283130

3129-
stringsolutionFileName=(solutionFile.Length==0)?String.Empty:Path.GetFileName(solutionFile);
3131+
stringsolutionFileName=(solutionPath.Length==0)?String.Empty:Path.GetFileName(solutionPath);
31303132

3131-
stringsolutionName=(solutionFile.Length==0)?String.Empty:Path.GetFileNameWithoutExtension(solutionFile);
3133+
stringsolutionName=(solutionPath.Length==0)?String.Empty:Path.GetFileNameWithoutExtension(solutionPath);
31323134

31333135
stringsolutionExtension=String.Empty;
3134-
if(solutionFile.Length>0&&Path.HasExtension(solutionFile))
3136+
if(solutionPath.Length>0&&Path.HasExtension(solutionPath))
31353137
{
3136-
solutionExtension=Path.GetExtension(solutionFile);
3138+
solutionExtension=Path.GetExtension(solutionPath);
31373139
}
31383140

31393141
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionDir.ToString(),solutionDirectory);
3140-
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionPath.ToString(),solutionFile);
3142+
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionPath.ToString(),solutionPath);
31413143
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionFileName.ToString(),solutionFileName);
31423144
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionName.ToString(),solutionName);
31433145
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionExt.ToString(),solutionExtension);
@@ -3172,6 +3174,19 @@ void SetupProjectGlobalPropertiesThatAllProjectSystemsMustSet()
31723174
}
31733175

31743176
this.buildProject.SetGlobalProperty(GlobalProperty.DevEnvDir.ToString(),installDir);
3177+
3178+
this.ProjectGlobalPropertiesThatAllProjectSystemsMustSet=newDictionary<string,string>()
3179+
{
3180+
{GlobalProperty.SolutionDir.ToString(),solutionDirectory},
3181+
{GlobalProperty.SolutionPath.ToString(),solutionPath},
3182+
{GlobalProperty.SolutionFileName.ToString(),solutionFileName},
3183+
{GlobalProperty.SolutionName.ToString(),solutionName},
3184+
{GlobalProperty.SolutionExt.ToString(),solutionExtension},
3185+
{GlobalProperty.BuildingInsideVisualStudio.ToString(),"true"},
3186+
{GlobalProperty.Configuration.ToString(),""},
3187+
{GlobalProperty.Platform.ToString(),""},
3188+
{GlobalProperty.DevEnvDir.ToString(),installDir}
3189+
};
31753190
}
31763191

31773192
privateclassBuildAccessorAccess

‎vsintegration/src/FSharp.ProjectSystem.Base/Project/Utilities.cs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ public static string SetStringValueFromConvertedEnum<T>(T enumValue, CultureInfo
719719
/// <param name="buildEngine">The build engine to use to create a build project.</param>
720720
/// <param name="fullProjectPath">The full path of the project.</param>
721721
/// <returns>A loaded msbuild project.</returns>
722-
publicstaticMicrosoft.Build.Evaluation.ProjectInitializeMsBuildProject(Microsoft.Build.Evaluation.ProjectCollectionbuildEngine,stringfullProjectPath)
722+
publicstaticMicrosoft.Build.Evaluation.ProjectInitializeMsBuildProject(Microsoft.Build.Evaluation.ProjectCollectionbuildEngine,stringfullProjectPath,IDictionary<String,String>globalProperties)
723723
{
724724
if(buildEngine==null)
725725
{
@@ -738,11 +738,11 @@ public static Microsoft.Build.Evaluation.Project InitializeMsBuildProject(Micros
738738

739739
if(buildProject==null)
740740
{
741-
varglobalProperties=newDictionary<string,string>()
741+
varlclGlobalProperties=(null==globalProperties)?newDictionary<string,string>():newDictionary<string,string>(globalProperties)
742742
{
743743
{"FSharpCompilerPath",Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}
744744
};
745-
buildProject=buildEngine.LoadProject(fullProjectPath,globalProperties,null);
745+
buildProject=buildEngine.LoadProject(fullProjectPath,lclGlobalProperties,null);
746746
buildProject.IsBuildEnabled=true;
747747
}
748748

@@ -756,7 +756,7 @@ public static Microsoft.Build.Evaluation.Project InitializeMsBuildProject(Micros
756756
/// <param name="fullProjectPath">The full path of the project.</param>
757757
/// <param name="exitingBuildProject">An Existing build project that will be reloaded.</param>
758758
/// <returns>A loaded msbuild project.</returns>
759-
publicstaticMicrosoft.Build.Evaluation.ProjectReinitializeMsBuildProject(Microsoft.Build.Evaluation.ProjectCollectionbuildEngine,stringfullProjectPath,Microsoft.Build.Evaluation.ProjectexitingBuildProject)
759+
publicstaticMicrosoft.Build.Evaluation.ProjectReinitializeMsBuildProject(Microsoft.Build.Evaluation.ProjectCollectionbuildEngine,stringfullProjectPath,IDictionary<String,String>globalProperties,Microsoft.Build.Evaluation.ProjectexitingBuildProject)
760760
{
761761
// If we have a build project that has been loaded with another file unload it.
762762
try
@@ -772,7 +772,7 @@ public static Microsoft.Build.Evaluation.Project ReinitializeMsBuildProject(Micr
772772
{
773773
}
774774

775-
returnUtilities.InitializeMsBuildProject(buildEngine,fullProjectPath);
775+
returnUtilities.InitializeMsBuildProject(buildEngine,fullProjectPath,globalProperties);
776776
}
777777

778778
publicstaticMicrosoft.Build.Evaluation.ProjectCollectionInitializeMsBuildEngine(Microsoft.Build.Evaluation.ProjectCollectionexistingEngine)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp