ligershark / template-builder

This project will output a NuGet package which can be used to help create Visual Studio Item Templates and Project templates
Other
42 stars 28 forks source link

FixNuGetPackageHintPathsWizard #82

Closed RehanSaeed closed 9 years ago

RehanSaeed commented 9 years ago

A wizard which fixes the hint paths for references to NuGet packages. This supports nuget.config files too using the NuGet.Core package. I also reference Microsoft.Build.dll to modify the project file.

I have done a fair amount of testing. with and without a nuget.config file. I have also tried using both relative and absolute paths in the nuget.config file. So far, it works well :+1: .

Possible Improvements

  1. If the wizard makes a change to the .csproj file to fix any hint paths, no file changed dialogue is shown to the user but the project is 'dirty' and the user has to hit the save button. I think this is a reasonable compromise but I'm open to suggestions on how to make this save automatic.
  2. I exit the wizard if the file is not a .csproj file. Not sure but this could probably work for VB too, so perhaps someone with VB knowledge could take a look.
codewithtyler commented 9 years ago

When I was updating the Add Template Reference feature for SideWaffle I had to programmatically adding the TemplateBuilder. This caused it to go into the 'dirty' state you mentioned in your first bullet. Since I already had an instance of the project (of type EnvDTE.Project currentProject) I was editing I just called the project save function. Maybe that can help you set it up to automatically save the project.

RehanSaeed commented 9 years ago

I was calling Save on the Microsoft.Build.Evaluation.Project instead of EnvDTE.Project. This was causing the 'something changed, do you want to discard your changes' dialogue to appear.

It seems to work now, thanks.

codewithtyler commented 9 years ago

On your second bullet, If I'm not mistaken VB projects have the same file structure? I don't see it any problem with having it do the exact same thing for those projects. @sayedihashimi do you have any thoughts on this?

RehanSaeed commented 9 years ago

Yes I wasn't sure about whether I should even add this check. Apart from VB projects, there may be others? F# Maybe?

Perhaps we should remove this check it would be better to leave this decision up to the developer using the wizard. What's your opinion?

sayedihashimi commented 9 years ago

Thanks a lot for the PR. I don't see any value in excluding any project type. If the wizard is in the .vstemplate its opted in. At the end all projects are MSBuild/VS projects so no harm. For DNX there won't be any HintPath elements to update.

I'll review more this weekend and hopefully merge it.

RehanSaeed commented 9 years ago

Excellent. I get a surprising number of complaints from newbie developers about this problem.

RehanSaeed commented 9 years ago

Updated to remove the .csproj check.

sayedihashimi commented 9 years ago

@RehanSaeed thanks for the PR. I will do the following.

@RehanSaeed To make your wizard more general purpose I think it would be good to populate a new custom parameter `$NuGetPackagesFolder$ so that the token can be used to do replacements where the packages folder is needed. For an example of how to populate that token see https://github.com/ligershark/template-builder/blob/master/src/TemplateBuilder/RootWizard.cs#L15.

RehanSaeed commented 9 years ago

I did a fair amount of testing but I'm sure I haven't covered everything. I definitely haven't covered non-C# projects. Cool, so we won't have to add this wizard ourselves as it will be included by default.

So do you mean just sticking this at the end:

// relativePackagesDirectoryPath is the relative path to the NuGet packages from the project.
GlobalDictionary["$NuGetPackagesFolder$"] = relativePackagesDirectoryPath;