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

Support Visual Studio 2017 .NET Core csproj Projects #96

Closed RehanSaeed closed 7 years ago

RehanSaeed commented 7 years ago

I get the following error for every NuGet package in my template project (.NET Core csproj) while trying to build my VSIX using Visual Studio:

C:\GitHub\Templates\packages\TemplateBuilder.1.1.4.9-beta\tools\ligershark.templates.targets(532,5): error MSB3030: Could not copy the file "C:\GitHub\Templates\Source\MVC6\Boilerplate.AspNetCore.Sample\Microsoft.Extensions.Configuration.CommandLine" because it was not found.

@RandomlyKnighted Any ideas if the new format is supported.

sayedihashimi commented 7 years ago

@RehanSaeed can you share a sample?

RehanSaeed commented 7 years ago

@sayedihashimi I have a branch. Just try opening the solution and building.

RehanSaeed commented 7 years ago

Doing some more investigation, I looked at the section in ligershark.templates.targets(532,5) causing the problem:

    <!-- TODO: now that we are copying the entire folder I think this step can be removed -->
    <Copy SourceFiles="@(_ls-NewProjFilesToCopyRaw->'$(_ls-TemplateFolder2)%(Identity)')"
          DestinationFiles="@(_ls-NewProjFilesToCopyRaw->'$(ls-DestTemplateOutputRoot)%(Identity)')">
      <Output TaskParameter ="CopiedFiles" ItemName="ls-temp-FilesCopied"/>
    </Copy>

I'm not sure what these lines do. The comment added by @sayedihashimi suggests that it's not needed, so I tried removing it and I was able to build a VSIX again. I've not validated the VSIX works yet as I've run out of time but it does contain my projects.

sayedihashimi commented 7 years ago

Yes I looked at that a while ago and I'm pretty sure we can remove that. Can you verify and send a PR? I'll release an update.

RehanSaeed commented 7 years ago

@sayedihashimi I just tested removing those lines:

  1. MVC 5 project creation is fine.
  2. .NET Core VS 2017 csproj project shows the following error dialog for each NuGet package installed in the project and then when the project is finally created, it is completely empty apart from the ReadMe.html file which opens.

untitled

sayedihashimi commented 7 years ago

How about non core projects? This could be a bug in the Roslyn project system.

RehanSaeed commented 7 years ago

My MVC 5 project (non .NET Core) gets created just fine.

sayedihashimi commented 7 years ago

@RehanSaeed can you share the .vsix which shows this behavior?

RehanSaeed commented 7 years ago

@sayedihashimi Here is a link to my VSIX on MyGet: https://www.myget.org/feed/aspnet-mvc-boilerplate/package/vsix/MvcBoilerplateVsix.Microsoft.dafd466d-39dc-487e-846b-7cf0e569821c/6.0.0

RehanSaeed commented 7 years ago

Raised this PR to partly fix this issue: https://github.com/ligershark/template-builder/pull/98.

Remaining Issue 1

I occasionally get the following random error that stops the VSIX building but I can use this potential fix: https://github.com/Microsoft/visualfsharp/pull/1751 which builds the VSIX but I still get build errors. This does leave me unable to debug.

error VSSDK1081: Problem occurred while extracting the vsix to the experimental extensions path.

Remaining Issue 2

I can generate a VSIX from Visual Studio 2017 but can't seem to run MSBuild.exe to generate the VSIX file. When running the command below, the project files and other files get copied and zipped but a VSIX file is not generated.

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe" /v:normal /p:Configuration="Release" /p:Platform=AnyCPU /p:DeployExtension=false /target:Build "C:/code/Templates/Source/Boilerplate.Vsix/Boilerplate.Vsix.csproj

Remaining Issue 3

When I run my code to edit and delete files, Visual Studio 2017 crashes with the error below.

System.ObjectDisposedException occurred
  HResult=0x80131622
  Message=Cannot access a disposed object.
  Source=Microsoft.VisualStudio.Validation
  StackTrace:
   at Microsoft.Verify.NotDisposed(IDisposableObservable disposedValue, String message)
   at Microsoft.VisualStudio.ProjectSystem.OnceInitializedOnceDisposed.EnsureInitialized(Boolean allowInitializing)
   at Microsoft.VisualStudio.ProjectSystem.ProjectTreeProviderBase.SubmitTreeUpdateAsync(TreeUpdateAsyncDelegate treeTransformation, IImmutableDictionary`2 updatedSources, TreeSubmissionOptions options, Int64& generationNumber, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies.DependenciesProjectTreeProvider.OnDependenciesChanged(Object sender, DependenciesChangedEventArgs e)
   at Microsoft.VisualStudio.Web.PackageManagement.SolutionExplorer.ProjectDependenciesAdapterBase.OnDependenciesChanged(DependenciesChangedEventArgs args)
   at Microsoft.VisualStudio.Web.PackageManagement.SolutionExplorer.ProjectDependenciesAdapterBase.InvalidateGraph(Object sender, EventArgs e)
   at Microsoft.VisualStudio.Web.PackageManagement.Npm.NpmPackageProvider.FirePackagesChanged()
   at Microsoft.VisualStudio.Web.PackageManagement.Npm.NpmPackageProvider.<RefreshRootNode>d__55.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Web.PackageManagement.Utilities.BatchingTaskScheduler.<Invoke>d__6.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
shanselman commented 7 years ago

:(

RehanSaeed commented 7 years ago

@shanselman Nice to see you share my pain. Building a VSIX is extremely frustrating process, every VS upgrade breaks something. Would like to move to dotnet new but VS is where the users are at. dotnet new could really use a UI in Visual Studio.

RehanSaeed commented 7 years ago

Have raised Build a UI in Visual Studio for dotnet new Templates as an issue.

sayedihashimi commented 7 years ago

Sorry for the delay. Work has been insane lately and at home I have a newborn young infant, so I'm finding it hard to get time. I'm starting to look at this. I'm guessing that the build logic for building a vstemplate into a vsix has some breaking changes. I'll reply back here after I get more info.

@RehanSaeed I can see the branch you linked above. Is it somewhere else?

RehanSaeed commented 7 years ago

@sayedihashimi Congrats on the baby, it takes about a year to get some sleep :) Although, I still sometimes have trouble with my little girl.

Merged into master. I'm planning to release a hacked together VSIX that:

  1. Shows a message box telling the developer to expect VS to crash and to just reopen the solution.
  2. Uses the fix in my PR.
  3. Builds on my machine using VS but not AppVeyor using MSBuild.

Not ideal but at least I can release something.

sayedihashimi commented 7 years ago

@RehanSaeed I've merged your PR and released it as TemplateBuilder.1.1.5-beta.nupkg. In that release I also made another minor change. When the .vstemplate file was being generated there were two ProjectItems listed

Those files must be coming in from .net core .targets/.props files but I haven't figured out which one yet. For now I've just special cased them and explicitly excluded them. If you see the same issue in your hacked version you can add those values to the ls-ProjectTemplateFilesToRemoveOnCopy item and you don't need to update the .targets file.

About the issue you mentioned about not being able to build the .vsix. I created a new vsix project in VS for testing templates and I was able to build the vsix with the following command. I think maybe -visualStudioVersion is the missing property that you should add but not sure. Also check to make sure you are building with the correct msbuild.exe.

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe" ".\VSIXProject1\VSIXProject1.csproj" /p:VisualStudioVersion=15.0 /m

I'm still looking into this issue. Will reply back here when I get more info to share.

RehanSaeed commented 7 years ago

Thanks for that!

Issue 1 Fixed

A lot of people are getting the error VSSDK1081: Problem occurred while extracting the vsix to the experimental extensions path. error. See MSDN and https://github.com/Microsoft/extendvs/issues/41. It's hitting the 254 file path length limit in .NET. The solution is to use a short product title, publisher name and template name (Not ideal).

Issue 2 Fixed

Thanks for that, I can do CI again! Your secret MSBuild argument /p:VisualStudioVersion=15.0 got it building.

Issue 3 Remains

I still get the following exception when overwriting files in the project when applying the users feature selections. This looks like a .NET Core tooling issue:

System.ObjectDisposedException occurred
  HResult=0x80131622
  Message=Cannot access a disposed object.
  Source=Microsoft.VisualStudio.Validation
  StackTrace:
   at Microsoft.Verify.NotDisposed(IDisposableObservable disposedValue, String message)
   at Microsoft.VisualStudio.ProjectSystem.OnceInitializedOnceDisposed.EnsureInitialized(Boolean allowInitializing)
   at Microsoft.VisualStudio.ProjectSystem.ProjectTreeProviderBase.SubmitTreeUpdateAsync(TreeUpdateAsyncDelegate treeTransformation, IImmutableDictionary`2 updatedSources, TreeSubmissionOptions options, Int64& generationNumber, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies.DependenciesProjectTreeProvider.OnDependenciesChanged(Object sender, DependenciesChangedEventArgs e)
   at Microsoft.VisualStudio.Web.PackageManagement.SolutionExplorer.ProjectDependenciesAdapterBase.OnDependenciesChanged(DependenciesChangedEventArgs args)
   at Microsoft.VisualStudio.Web.PackageManagement.SolutionExplorer.ProjectDependenciesAdapterBase.InvalidateGraph(Object sender, EventArgs e)
   at Microsoft.VisualStudio.Web.PackageManagement.Npm.NpmPackageProvider.FirePackagesChanged()
   at Microsoft.VisualStudio.Web.PackageManagement.Npm.NpmPackageProvider.<RefreshRootNode>d__55.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Web.PackageManagement.Utilities.BatchingTaskScheduler.<Invoke>d__6.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
RehanSaeed commented 7 years ago

Released an update. Issue 3 seems to be gone the last time I tried after updating VS. Will create a new VS tooling issue if it re-occurs.

I still show a modal warning dialogue telling the user to expect VS to crash just in case :(.