Shinya Watanabe

Please teach us how to support temporary projects.

Please teach us the topics about temporary projects in Visual Studio 2005 SDK.

Best Regards.
Shinya Watanabe


Re: Visual Studio Extensibility How to support Temporary Projects

Shinya Watanabe

I asked about temporary projects.
There is no reply to me.
Meanwhile, I was referring to help and the IDL file of SDK.

I found IvsDeferredSaveProject Interface.
I think that this interface is related, and is it correct
Moreover, isn't there sample source

Best Regards.
Shinya Watanabe





Re: Visual Studio Extensibility How to support Temporary Projects

Douglas Hodges

What you are calling "temporary projects" is what we normally refer to as "zero-impact" projects or "deferred save projects". You are correct that projects that support this feature will implement the IVsDeferredSaveProject interface. There currently is no sample for the implementation of zero-impact projects. In the mean time I can give you more information on this feature:

Zero impact projects were created to simplify the experience of creating and playing with projects. In vb6, users were able to create new projects and immediately begin experimenting with them without having to select a location to save to. In fact, the user might even decide not to save the project anywhere. The main scenario is the following: User creates a new project and plays around with it for a while. The user is able to play with the project without being initially prompted to save. The project is not visibly persisted to disk until the user saves.

Zero-impact projects are a profile point and a Tools | Options switch. The zero-impact projects option appears on the Tools | Options | Projects & Solutions menu. The option appears as:
 ? Save new projects when created

The following must be true for a project to be zero-impact:
    ? ¡°Set project name/location during creation¡± is enabled via Tools | Options or the profile
    ? The template supports zero-impact projects

When working with the zero-impact project, it will always appear to the user that a zero-impact project is in-memory, even though in reality the project is being persisted to a hidden directory.

Whenever performing an Open or Add gesture, the gesture should start in the standard default directory, not in the Zero Impact Project directory. Examples:
    o Open Project should default into the standard default directory, which is My Documents\Visual Studio Projects
    o Add Reference -> Project (Tab) -> Browse should default into the standard default directory, which is My Documents\Visual Studio Projects
    o Affected gestures:
 ? Open Project
 ? Open Website
 ? Add Existing Project
 ? Add Existing Website
 ? Add Reference -> Project -> Browse

Note the following additional behaviors when working with a zero impact project:
    ? A "zero-impact" project cannot be added to an existing solution.
    ? It is possible to create simultaneous zero impact projects, each in a separate shell instance.
    ? The zero-impact project setting is independent of solutionless project setting.
    ? If a user chooses to delete a file in a zero impact project before saving the project, no special warnings are shown.
    ? Only one project can be in the zero-impact state. It is not possible to have a solution with multiple zero-impact projects; the original project must be saved before additional projects can be added.
    ? While working with the ZIP, the user can close and reopen items in the project without losing changes and without needing to perform an explicit save. Any changes are persisted (we can do this by maintaining a lock on the file).

The following changes are made to the menus/properties when working with zero impact projects:
    ? Properties that contain a path (for solution, project, items) should not be displayed in the property browser.
    ? Creation of solution folders (even implicitly via add new solution item or add existing solution item) is disabled (¡°Add Solution Folder¡± is not a context menu option on the solution)
    ? Commands to add new or existing webs are disabled.
    ? it is not possible to remove the project from the solution. (¡°Remove¡± is not a context menu option on the project)
    ? When the solution or project is the selected context in the solution explorer, the ¡°Close¡± command should be hidden since it doesn¡¯t do anything.
    ? ¡°Save All¡± is not presented on the file menu. Instead, the option ¡°Save Project¡± is presented.

There are several actions a user can perform which will cause a prompt to save the project. These actions are:
1. File -> Add to Source Control
2. File -> Add -> New Project
3. File -> Add -> Existing Project
4. File -> New -> Project
5. File -> New -> Website
6. File -> Open -> Project
7. File -> Open -> Website
8. Close
9. File -> New -> Blank Solution

If the user attempts to perform one of these actions, we will alert the user that the action cannot be performed without a save, and give the user an opportunity to save. The user will first be prompted that the gesture s/he has performed requires a save. A unique dialog will be shown depending on which of the three actions the user has performed.

Marking a project template as zero-impact is done via modification to the .VSTEMPLATE file or the .VSDIR file depending on which is being used. A .VSTEMPLATE file should include the following tag in the <TemplateData> section to enable zero-impact project creation:
    <PromptForSaveOnCreation>false</PromptForSaveOnCreation>
If a .VSDIR file is used then the VSDIRFLAG_DeferredSaveProject (0x00000080) should be specified. When a project is being created as a zero-impact project, the project name will be automatically generated, as will the location, which will be at some temporary location (imitating the "in-memory" project experience). Zero-impact projects will be persisted under:
 [%system%]\Documents and Settings\[%user%\Application Data

During the time the user is interacting with a zero-impact project pre-save, the project is persisted to this directory.  The directory will be emptied and reused on each creation of a project in the zero impact state. Note that for the RunAs normal user scenario, a user with the appropriate credentials should be able to access the Application Data directory correctly and work with zero impact projects. When the project is created, CPF_DEFERREDSAVE is passed as one of the grfCreateFlags to IVsProjectFactory::CreateProject and/or IVsAggregatableProject::InitializeForOuter. The solution will be limited to containing one project, and nothing will be considered "dirty" while the solution/project are "zero-impact". When the user chooses to save the project permanently, he will use File.SaveAll, which will present him with a file browser with which he is to choose the new filename/location for his project file.  Once he chooses the filename, SaveProjectToLocation is called and the project must save itself to the specified filename and save all its other contents to the folder where the filename was specified.  At this point, the solution/project will no longer be considered "zero-impact" and normal solution/project operations will be available. If the project has certain actions that can not be performed in the zero-impact state, then the project can cause the user to be prompted to save a permanent copy of the project using the IVsSolution3::CheckForAndSaveDeferredSaveSolution method.






Re: Visual Studio Extensibility How to support Temporary Projects

tyou_aki

Hi,Douglas Hodges,

Thank you for your reply.
But I want to know how to start the implementation of zero impact project. I want to implement a development environment of my own by VSIP.
Could you tell me how should I do The information from VSIP document seems not enough.
< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />







Re: Visual Studio Extensibility How to support Temporary Projects

Shinya Watanabe

Dear Douglas

Thank you for reply.
And thank you for your kindness in last year's Developer Lab.

We confirmed Visual C# referring to your answer.

It is thought that it is not supported by VC # in the following four items.

---
£±£®Creation of solution folders (even implicitly via add new solution item or add existing solution item) is disabled (¡°Add Solution Folder¡± is not a context menu option on the solution).
£²£®it is not possible to remove the project from the solution. (¡°Remove¡± is not a context menu option on the project).
£³£®When the solution or project is the selected context in the solution explorer, the ¡°Close¡± command should be hidden since it doesn¡¯t do anything.
£´£®¡°Save All¡± is not presented on the file menu. Instead, the option ¡°Save Project¡± is presented.
---

Should I support these four items as a language
Please confirm it.

Best Regards.
Shinya Watanabe




Re: Visual Studio Extensibility How to support Temporary Projects

Shinya Watanabe

Dear Douglas

I have another question.

It wants to achieve the making procedure of the Zero-impact project, and teach how to implement, please.

Best Regards.
Shinya Watanabe




Re: Visual Studio Extensibility How to support Temporary Projects

tyou_aki

Hi,Douglas

In my opinion, the making ZIP procedures as follows:


1. While creating a new project,  it is necessary to get the state of SAVE NEW PROJECTS WHEN CREATED  in OPOTION PAGE.

2. If the check box is not checked, that means the user want to creat ZIP. In .VSDIR file, the relate node is set to FALSE.

3. The creation of ZIP is exactly same as normal.

4. When other operations relate to ZIP such as CLOSE and SAVE ALL and so on are triggered, it just needs to get the value of relate node in .VSDIR file.

5. If the value is FALSE, that means current project is ZIP, the ZIP related functions are triggered.

I could be wrong in all probability, may I share your thought


Best regards.







Re: Visual Studio Extensibility How to support Temporary Projects

Douglas Hodges

Regarding your questions:

1. While creating a new project,  it is necessary to get the state of SAVE NEW PROJECTS WHEN CREATED  in OPOTION PAGE.

[Douglas Hodges] No, this is not true. you do not need to get the state of the checkbox in Tools.Options. If the user is creating a ZIP project then the CPF_DEFERREDSAVE flag is passed to your IVsProjectFactory::CreateProject method. You might not actually really need this information at this point (see question 3 below). You can always ask at any point to see if the current Solution is actually in deferred save mode by calling IVsSolution::GetProperty(VSPROPID_DeferredSaveSolution, ...)

For example:
VARIANT bDeferredSaveSolution;
if(SUCCEEDED(pIVsSolution->GetProperty(VSPROPID_DeferredSaveSolution,&bDeferredSaveSolution)))
   
*pfHide = V_BOOL(&bDeferredSaveSolution);



2. If the check box is not checked, that means the user want to creat ZIP. In .VSDIR file, the relate node is set to FALSE.

[Douglas Hodges] You don't need to change the values in your .VSDIR file depending on the Tools Options choice of the user. Basically you will mark your VSDIR or VSTemplate file stating that you support the ZIP feature. The IDE will decide whether to actually create a project in this mode depending on the users choice in Tools Options. This is done for you. To mark that you support ZIP you do the following:
    A .VSTEMPLATE file should include the following tag in the <TemplateData> section to enable zero-impact project creation:
    <PromptForSaveOnCreation>false</PromptForSaveOnCreation>
If a .VSDIR file is used then the VSDIRFLAG_DeferredSaveProject (0x00000080) should be specified.


3. The creation of ZIP is exactly same as normal.

[Douglas Hodges] Yes. This is true.


4. When other operations relate to ZIP such as CLOSE and SAVE ALL and so on are triggered, it just needs to get the value of relate node in .VSDIR file.

[Douglas Hodges] No, you don't have to do anything here. The IDE handles these commands correctly for you. To be accurate, the SAVE ALL command is still enabled but will cause the ZIP project to be prompted for a permanent save location. The CLOSE SOLUTION/PROJECT command is still enabled and will prompt the user if they want to save or discard the project. If the user chooses to save the project then they will be prompted for the permanent location of the project before the project is saved/closed. All of this is handled for you; you do not have anything to do to handle this.


5. If the value is FALSE, that means current project is ZIP, the ZIP related functions are triggered.

[Douglas Hodges] Based on 4. above, this is also wrong. The ZIP related functions are handled by the IDE and are triggered by the state of the Solution -- not the state of the flags in the VSDIR file. Yes the Tools Options value "Save new projects when created" determines whether projects are created in ZIP (deferred save) mode or not.


There is not much you need to do to support zero-impact projects. The IDE's implementation of the Solution takes care of the following for you:

    1.Creation of solution folders (even implicitly via add new solution item or add existing solution item) is disabled (¡°Add Solution Folder¡± is not a context menu option on the solution).
    2.it is not possible to remove the project from the solution. (¡°Remove¡± is not a context menu option on the project).
    3.Implementation of CLOSE SOLUTION/PROJECT and SAVE ALL/SAVE PROJECT  commands.


The only part you are responsible is for implementing the following:

    1. Implement IVsDeferredSaveProject::SaveProjectToLocation. This is the biggest part of the implementation. Depending on the hookup between your project system and the in memory compiler/language service this can be tricky. Some of the steps that you will need to take are the following:
         a. Call IVsSolution::QueryRenameProject prior to accepting the new location for the project. If this method passes back *pfRenameCanContinue==FALSE, then you should abort the save process.
         b. Then basically you need to shut down your current in-memory compiler/language service. This is necessary so you can copy all of the project files to a new location.
         c. Copy all of the project files to the new location.
         d. Now you need to get all the open documents renamed so that their entries in the running document table point to the correct locations on disk.  You can do this by calling the HierUtil function LUtilRenameOpenDoc on each of the open files in your project.
         e. Now you should start your current in-memory compiler and language service back up, so they will start using the files in the new location.
         f. Call IVsSolution::OnAfterRenameProject once you have copied all the project files to the new location.

    2. The other requirement of the implementation is to try to hide the temporary project location from the user. Any properties shown in the Properties Window or Property Pages that contain the path should be hidden. For the Properties Window, this is achieved by implementing IVsPerPropertyBrowsing on your browse objects. There is a HideProperty method that is called with the DSIPID of the property before it is shown. Some of the properties that the VB/C# project hides are "Project Folder" for the project node and "Full Path" for the file nodes, reference nodes, etc.

E.g.:

HRESULT CMyProjectProperties::HideProperty(DISPID dispid, BOOL* pfHide)
{
   
if (!pfHide)
       
return E_INVALIDARG;
   
if(MYPROJPROPID_FullPath == dispid)
   
{ //If the solution is a 'DeferredSaveSolution' AKA 'Zero-Impact project' then we shouldn't be displaying the full path
       
*pfHide = FALSE;
       
VARIANT bDeferredSaveSolution;
       
if(SUCCEEDED(_VxModule.GetIVsSolution()->GetProperty(VSPROPID_DeferredSaveSolution,&bDeferredSaveSolution)))
           
*pfHide = V_BOOL(&bDeferredSaveSolution);
       
return S_OK;
   
}
   
...
}

Basically the goal is to hide the temporary project location from the user. We are trying to pull off the illusion that the project is temporary in memory and not yet saved on disk.

I hope this helps,






Re: Visual Studio Extensibility How to support Temporary Projects

tyou_aki

Hi,Douglas,

Thank you very much.




Re: Visual Studio Extensibility How to support Temporary Projects

tyou_aki

Dear Douglas,

Thank you very much.
After your reply, I have made a great progress in my work.

But I have a slight difficulty about implementation of SaveProjectToLocation. I defined a class which inherited the interface IVsDeferredSaveProject and implement the vitural function SaveProjectToLocation. When I save my ZIP, the "Save" button was clicked and  a messagebox showed up,with information likes "The function has not been impleted." In other words, the VS can't not find the function SaveProjectToLocation impleted in my own class.

Before, I also impleted funtion for other interface similarly and successed.

I have checked my code and looked for the reasons. But I only found that the difference is that the interface IVsDeferredSaveProject  is defined in VSShell80 While other interfaces in which I have successed are defined in VSShell.

Now I am confused to some extent.

Could you help me to analyse the reason Expecting your reply.



Best regards.



.





Re: Visual Studio Extensibility How to support Temporary Projects

Douglas Hodges

The IDE retrieves the pointer to your IVsDeferredSaveProject implementation by calling QueryInterface on your Project object. This is the object that implements IVsHierarchy and IVsProject interfaces (among others). I would guess that you need to add an implementation of IVsDeferredSaveProject interface to your Project object and then delegate the method call of SaveProjectToLocation to the same method on your new class.




Re: Visual Studio Extensibility How to support Temporary Projects

Dmitry Pavlov

Hi Douglas,

I have created a new thread here - "MPF bug: Solution is not saved when "Save new projects when created" is unchecked".

Could you please have a look at Your input will be much appreciated!

Thanks,