@@ -21,7 +21,7 @@ namespace Microsoft.VisualStudio.Package
2121 /// Creates projects within the solution
2222 /// </summary>
2323 [ CLSCompliant ( false ) ]
24- public abstract class ProjectFactory : Microsoft . VisualStudio . Shell . Flavor . FlavoredProjectFactoryBase , IVsProjectUpgradeViaFactory
24+ public abstract class ProjectFactory : Microsoft . VisualStudio . Shell . Flavor . FlavoredProjectFactoryBase
2525 {
2626 #region fields
2727 private Microsoft . VisualStudio . Shell . Package package ;
@@ -194,173 +194,5 @@ private IProjectEvents GetProjectEventsProvider()
194194 }
195195
196196 #endregion
197-
198- #region IVsProjectUpgradeViaFactory
199- private string m_lastUpgradedProjectFile ;
200- private const string SCC_PROJECT_NAME = "SccProjectName" ;
201- private string m_sccProjectName ;
202- private const string SCC_AUX_PATH = "SccAuxPath" ;
203- private string m_sccAuxPath ;
204- private const string SCC_LOCAL_PATH = "SccLocalPath" ;
205- private string m_sccLocalPath ;
206- private const string SCC_PROVIDER = "SccProvider" ;
207- private string m_sccProvider ;
208- public virtual int GetSccInfo ( string projectFileName , out string sccProjectName , out string sccAuxPath , out string sccLocalPath , out string provider )
209- {
210- // we should only be asked for SCC info on a project that we have just upgraded.
211- if ( ! String . Equals ( this . m_lastUpgradedProjectFile , projectFileName , StringComparison . OrdinalIgnoreCase ) )
212- {
213- sccProjectName = "" ;
214- sccAuxPath = "" ;
215- sccLocalPath = "" ;
216- provider = "" ;
217- return VSConstants . E_FAIL ;
218- }
219- sccProjectName = this . m_sccProjectName ;
220- sccAuxPath = this . m_sccAuxPath ;
221- sccLocalPath = this . m_sccLocalPath ;
222- provider = this . m_sccProvider ;
223- return VSConstants . S_OK ;
224- }
225-
226- public virtual int UpgradeProject_CheckOnly ( string projectFileName , IVsUpgradeLogger upgradeLogger , out int upgradeRequired , out Guid newProjectFactory , out uint upgradeCapabilityFlags )
227- {
228- newProjectFactory = GetType ( ) . GUID ;
229- upgradeCapabilityFlags = 0 ; // VSPPROJECTUPGRADEVIAFACTORYFLAGS: we only support in-place upgrade with no back-up
230-
231- ProjectRootElement project = ProjectRootElement . Open ( projectFileName ) ;
232-
233- // only upgrade known tool versions.
234- if ( string . Equals ( "3.5" , project . ToolsVersion , StringComparison . Ordinal ) || string . Equals ( "2.0" , project . ToolsVersion , StringComparison . Ordinal ) )
235- {
236- upgradeRequired = 1 ;
237- return VSConstants . S_OK ;
238- }
239-
240- upgradeRequired = 0 ;
241- return VSConstants . S_OK ;
242- }
243- public virtual int UpgradeProject ( string projectFileName , uint upgradeFlag , string copyLocation , out string upgradeFullyQualifiedFileName , IVsUpgradeLogger logger , out int upgradeRequired ,
244- out Guid newProjectFactory )
245- {
246- uint ignore ;
247-
248- this . UpgradeProject_CheckOnly ( projectFileName , logger , out upgradeRequired , out newProjectFactory , out ignore ) ;
249- if ( upgradeRequired == 0 )
250- {
251- upgradeFullyQualifiedFileName = projectFileName ;
252- return VSConstants . S_OK ;
253- }
254-
255- string projectName = Path . GetFileNameWithoutExtension ( projectFileName ) ;
256- upgradeFullyQualifiedFileName = projectFileName ;
257-
258- // Query for edit
259- IVsQueryEditQuerySave2 queryEdit = site . GetService ( typeof ( SVsQueryEditQuerySave ) ) as IVsQueryEditQuerySave2 ;
260-
261- if ( queryEdit != null )
262- {
263- uint editVerdict ;
264- uint queryEditMoreInfo ;
265- const tagVSQueryEditFlags tagVSQueryEditFlags_QEF_AllowUnopenedProjects = ( tagVSQueryEditFlags ) 0x80 ;
266-
267- int hr = queryEdit . QueryEditFiles (
268- ( uint ) ( tagVSQueryEditFlags . QEF_ForceEdit_NoPrompting | tagVSQueryEditFlags . QEF_DisallowInMemoryEdits | tagVSQueryEditFlags_QEF_AllowUnopenedProjects ) ,
269- 1 , new [ ] { projectFileName } , null , null , out editVerdict , out queryEditMoreInfo ) ;
270- if ( ErrorHandler . Failed ( hr ) )
271- {
272- return VSConstants . E_FAIL ;
273- }
274-
275- if ( editVerdict != ( uint ) tagVSQueryEditResult . QER_EditOK )
276- {
277- if ( logger != null )
278- {
279- logger . LogMessage ( ( uint ) __VSUL_ERRORLEVEL . VSUL_ERROR , projectName , projectFileName ,
280- SR . GetString ( SR . UpgradeCannotOpenProjectFileForEdit ) ) ;
281- }
282- return VSConstants . E_FAIL ;
283- }
284-
285- // If file was modified during the checkout, maybe upgrade is not needed
286- if ( ( queryEditMoreInfo & ( uint ) tagVSQueryEditResultFlags . QER_MaybeChanged ) != 0 )
287- {
288- this . UpgradeProject_CheckOnly ( projectFileName , logger , out upgradeRequired , out newProjectFactory , out ignore ) ;
289- if ( upgradeRequired == 0 )
290- {
291- if ( logger != null )
292- {
293- logger . LogMessage ( ( uint ) __VSUL_ERRORLEVEL . VSUL_INFORMATIONAL , projectName , projectFileName ,
294- SR . GetString ( SR . UpgradeNoNeedToUpgradeAfterCheckout ) ) ;
295- }
296-
297- return VSConstants . S_OK ;
298- }
299- }
300- }
301-
302- // Convert the project
303- Microsoft . Build . Conversion . ProjectFileConverter projectConverter = new Microsoft . Build . Conversion . ProjectFileConverter ( ) ;
304- projectConverter . OldProjectFile = projectFileName ;
305- projectConverter . NewProjectFile = projectFileName ;
306- ProjectRootElement convertedProject = null ;
307- try
308- {
309- convertedProject = projectConverter . ConvertInMemory ( ) ;
310- }
311- catch ( Exception ex )
312- {
313- if ( logger != null )
314- logger . LogMessage ( ( uint ) __VSUL_ERRORLEVEL . VSUL_ERROR , projectName , projectFileName , ex . Message ) ;
315- }
316-
317- if ( convertedProject != null )
318- {
319- this . m_lastUpgradedProjectFile = projectFileName ;
320- foreach ( ProjectPropertyElement property in convertedProject . Properties )
321- {
322- switch ( property . Name )
323- {
324- case SCC_LOCAL_PATH :
325- this . m_sccLocalPath = property . Value ;
326- break ;
327- case SCC_AUX_PATH :
328- this . m_sccAuxPath = property . Value ;
329- break ;
330- case SCC_PROVIDER :
331- this . m_sccProvider = property . Value ;
332- break ;
333- case SCC_PROJECT_NAME :
334- this . m_sccProjectName = property . Value ;
335- break ;
336- default :
337- break ;
338- }
339- }
340- try
341- {
342- convertedProject . Save ( projectFileName ) ;
343- }
344- catch ( Exception ex )
345- {
346- if ( logger != null )
347- logger . LogMessage ( ( uint ) __VSUL_ERRORLEVEL . VSUL_ERROR , projectName , projectFileName , ex . Message ) ;
348- return VSConstants . E_FAIL ;
349- }
350- if ( logger != null )
351- {
352- logger . LogMessage ( ( uint ) __VSUL_ERRORLEVEL . VSUL_STATUSMSG , projectName , projectFileName ,
353- SR . GetString ( SR . UpgradeSuccessful ) ) ;
354- }
355- return VSConstants . S_OK ;
356-
357- }
358-
359- this . m_lastUpgradedProjectFile = null ;
360- upgradeFullyQualifiedFileName = "" ;
361- return VSConstants . E_FAIL ;
362- }
363-
364- #endregion
365197 }
366198}
0 commit comments