drewnoakes on master
Fix links to blog posts A prev… Merge pull request #334 from tm… (compare)
AArnott on master
Replace old, redundant doc with… (compare)
drewnoakes on AArnott-patch-1
drewnoakes on master
Fix code sample for obtaining t… Merge pull request #333 from mi… (compare)
AArnott on AArnott-patch-1
Fix code sample for obtaining t… (compare)
I'd like to export a MEF component whose lifetime matches that of my custom project type -- much like the ProjectNode
class in MPFProj. My expectation, based on the docs, is that IProjectDynamicLoadComponent
might be an option. However, adding a minimal implementation of this interface results in the UnloadAsync
method never getting invoked.
[Export(ExportContractNames.Scopes.UnconfiguredProject, typeof(IProjectDynamicLoadComponent))]
[AppliesTo(MyProjectCapabilities.MyProject)]
internal class MyProjectDynamicLoadComponent : IProjectDynamicLoadComponent
{
[Import]
public UnconfiguredProject UnconfiguredProject { get; set; }
public async Task LoadAsync()
{
await Task.CompletedTask;
}
public async Task UnloadAsync()
{
await Task.CompletedTask;
}
}
If I implement IDisposable
, then that is called when the associated project is closed or unloaded. So, I "think" I can get the behavior I want, but it troubles me that I never see UnloadAsync
.
Is this the most direct way to have an export that tracks the lifetime automatically of a project?
I'm trying to distribute a NuGet package as part of my custom project type VSIX, as per these docs:
https://docs.microsoft.com/en-us/nuget/visual-studio-extensibility/visual-studio-templates
The package is properly deployed and the .vstemplate
file seems to be working because the packages.config
file is automatically created by the new project template. And, the packages.config
file does have the correct content in it.
However, when I execute the "Manage NuGet Packages" command, I get the error below:
Note that I have declared the PackageReferences
capability, though I don't think it applies here.
PackageReferences
capability is for projects which support PackageReference
s in the project file, I think it's available for all project systems now (since VS 15.5 or 15.6?), and the wizard shouldn't generate a packages.config, as it's not compatible... also see NuGet/Home#4693
@jp2masa Oh, wow. I was poking around those issues and thought I hit a dead end because most references lead to this:
That didn't reference anything on NuGet. So, if PackageReference
works, then that's great. And, Andrew Arnott's comment about not using that wizard-based pattern anymore would certainly apply.
It seems all I need to do is delete all the stuff I thought I needed, and then just have the PackageReference
.
@jp2masa So, if I simply add a PackageReference
, then I actually see the same error when I execute "Manage NuGet Packages" on the project.
And, "Manage NuGet Packages for Solution", doesn't list my custom project type in the list of projects.
I've added XAML rules files for PackageReference
and ResolvedPackageReference
, taken from the .NET project system.
I've also added those to the Imports
in my targets file.
Is there another step perhaps I missed?
Thanks in advance.
packages.config
style instead of PackageReference
.packages.config
and adds it to the project, and downloads the package to a solution-level packages
folder.PackageReference
selected in Tools -> Options as the default and I'm even setting the RestoreProjectStyle
property in my project file to PackageReference
.packages.config
style, installing the package does not inject the automatic Import
of my build\<myPackageId>.targets
into the project file, even though the package manager says installation succeeded.PackageReference
is correctly generated.packages.config
style is used (as that's all C++ supports, I believe), and the Import
of my build\<myPackageId>.targets
is correctly inserted into the project file .
Dependencies
node in Solution Explorer.
packages.config
. <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Microsoft.VisualStudio.VCProjectEngine
namespace, but can't find a way to instantiate the VCProjectEngine
interface.
VCProjectEngine
. Rather, you start with an IVsHierarchy
:hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, __VSHPROPID.VSHPROPID_ExtObject, out var automationProject);
var codeModel = automationProject.CodeModel as VCCodeModel;
var vcProject = automationProject.Object as VCProject;
var fileCodeModel = automationProject.ProjectItems.Item(i).FileCodeModel as VCFileCodeModel;
@jp2masa , If you're interested, I see the same behavior with the default Project Type template. I attached a minimal project system. All I did was:
Microsoft.Common.targets
.RestoreProjectStyle
property.Try adding any NuGet package to it via the package manager. It succeeds, but adds a packages.config
and doesn't add the required imports to the project file.
PackageReference
in my project template, then it will restore and build fine.TargetFramework
thing looked promising, but this is, of course, not a .NET Framework project - it's my own, so not sure what value to put there anyway.