Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 08 22:25
    twsouthwick commented #298
  • Oct 15 22:45
    tgeng commented #137
  • Oct 03 21:56
    KristianJakubik edited #330
  • Oct 03 21:51
    KristianJakubik commented #330
  • Oct 03 21:50
    KristianJakubik commented #330
  • Oct 03 21:47
    KristianJakubik opened #330
  • Oct 01 21:49
    aodl edited #329
  • Oct 01 21:45
    aodl opened #329
  • Aug 30 11:32
    KristianJakubik edited #328
  • Aug 30 11:21
    KristianJakubik edited #328
  • Aug 30 11:20
    KristianJakubik reopened #328
  • Aug 30 11:20
    KristianJakubik edited #328
  • Aug 30 11:20
    KristianJakubik edited #328
  • Aug 30 11:10
    KristianJakubik closed #328
  • Aug 30 11:10
    KristianJakubik opened #328
  • Aug 26 22:59
    tgeng commented #234
  • Aug 26 22:01
    tgeng commented #234
  • Aug 26 21:16
    tgeng commented #234
  • Aug 05 06:48
    aodl commented #130
  • Aug 05 06:21
    aodl commented #130
Kirk Fertitta
@kfertitta

Can anyone comment on the practical difference between accessing the active ConfiguredProject in the following two ways (other than the obvious async different):

UnconfiguredProject.Services.ActiveConfiguredProjectProvider.ActiveProjectConfiguration

versus

UnconfiguredProject.GetSuggestedConfiguredProjectAsync()
Kirk Fertitta
@kfertitta

I'm trying to read the value of a project property that is defined inside a target, like so:

  <Target Name="Test">
    <PropertyGroup>
      <Foo>Kirk</Foo>
    </PropertyGroup>
  </Target>

Thus, the target must run before the Foo property has a value. In our MPFProj-based project system, this worked fine -- just run the target and read the property, as per normal. MPFProj uses the MSBuild API directly.

In an attempt to do the same in our new CPS-based project, we use IBuildProject.BuildAsync and GetEvaluatedPropertyValueAsync. However, the Foo property returns an empty string.

Here is the code:

                        var buildResult = await configuredProject.Services.Build.BuildAsync(new[] { "Test" }, cancellationToken: default, includeUnsavedChanges: true);
                        Debug.Assert(buildResult.OverallResult == BuildResultCode.Success);

                        var f1 = await configuredProject.Services.ProjectPropertiesProvider.GetCommonProperties().GetEvaluatedPropertyValueAsync("Foo");

                        using (var access = await projectLockService.ReadLockAsync())
                        {
                            var project = await access.GetProjectAsync(configuredProject);
                            var projectInstance = BuildManager.DefaultBuildManager.GetProjectInstanceForBuild(project);
                            var success = projectInstance.Build("Test", loggers: null);
                            Debug.Assert(success);

                            var f2 = projectInstance.GetPropertyValue("Foo");
                        }

In the above f1 is an empty string, while f2 correctly prints out the Foo property's value of "Kirk".

Any thoughts on why? It makes me nervous about using IBuildProject as opposed to MSBuild directly.

Thanks in advance.

Kirk Fertitta
@kfertitta
Anybody out there?
jp2masa
@jp2masa
@kfertitta do you still need help with that? the easiest way would be returning the value from a target I think, you can also create a rule and set the data source to the target results if you want
Kirk Fertitta
@kfertitta
@jp2masa Thanks for chiming in. This is still unresolved and feels important/fundamental.
Trouble is, this is a general usage issue as I have LOTS of target-scoped properties like this.
It may be more practical to forego IBuildProject altogether if it can't handle this and just use the MSBuild API.
I can sorta see what's going on -- the ConfiguredProject is probably tied to a ProjectInstance under the covers, and that's not getting updated when you do a build.
Feels like there should be a way to "kick it" and either get an updated ConfiguredProject instance or something.
It's all layered on top of MSBuild, so just feels like I'm missing something.
jp2masa
@jp2masa
I don't think that you're supposed to get properties from targets that often... anyway, did you try using this: https://github.com/Microsoft/VSProjectSystem/blob/master/doc/automation/obtaining_the_MSBuild.Project_from_CPS.md ?
Kirk Fertitta
@kfertitta
@jp2masa , Indeed, I did exactly that. See the code snippet above. I take the project obtained in that fashion and feed it to the MSBuild API in order to get the correct results.
But, there are many actions that could cause properties to change, so I'm unclear on when/how/if the ConfiguredProject is updated in general if this doesn't work.
jp2masa
@jp2masa
that's why you have to acquire the lock I think, so that the project that you get is always up-to-date
Kirk Fertitta
@kfertitta
Yeah, but after leaving the using, reading the properties again still returns an empty string.
I did think about the effect of the lock.
But, build doesn't require a lock, and lots of things can change as a result of a build. Item transforms, etc, etc.
jp2masa
@jp2masa
that's because targets are associated to building, and in VS the project isn't building, you just have a project instance
if you build a target, it wouldn't make sense to affect the instance I think?
Kirk Fertitta
@kfertitta
Well, it has to. And it does in MSBuild directly. The f2 variable prints the correct value -- the value of a property that's only defined in a target.
And MSBuild is underneath the ConfiguredProject.
jp2masa
@jp2masa
right, what I mean is that for example you build the same target multiple times, and that target appends something to a property, you would get the appended part multiple times, that's not what you want
so the project system holds an evaluated project, but only creates instances when building a target I think
Kirk Fertitta
@kfertitta
Hmmn, yeah could be.
That would explain at least part of the behavior.
Seems like my only alternative is to do it with MSBuild, or...
take my properties out of the target.
But, they are defined in terms of task outputs within the target, so the scoping is appropriate from an MSBuild perspective.
jp2masa
@jp2masa
in that case you would return the results from a target and create a rule to consume them
Kirk Fertitta
@kfertitta

Hey, @jp2masa , while you're "here", did you have any thoughts on the question above about which to use between:

UnconfiguredProject.GetSuggestedConfiguredProjectAsync

and

UnconfiguredProject.Services.ActiveConfiguredProjectProvider.ActiveConfiguredProject
jp2masa
@jp2masa
I usually use the first one, not sure about the difference, maybe the second one can be null?
Kirk Fertitta
@kfertitta
Yeah, first one definitely uses more rules and probably can't be null.
It's just that the SDK templates generate imports and such on the XXXUnconfiguredProject class that access the ActiveConfiguredProject and even have the ActiveConfiguredProject wrapper class.
Seem like a lot of things pointing towards those properties, but I, like you, get the impression that it can be null.
Maybe the distinction is more important outside of VS (which I don't care about ... yet) ???
jp2masa
@jp2masa
I honestly never understood why those classes come in the template, I simply removed them and they just make things harder to understand IMO... I also never use ActiveConfiguredProject I think
it's probably null when the project system is being initialized and there's no active configuration yet
maybe for example when exporting a project capabilities provider at the unconfigured project scope, the first time it's queried there's no active configuration I think
Kirk Fertitta
@kfertitta
Good, we're on the same page then.
Thanks much for your help.
Kirk Fertitta
@kfertitta
@jp2masa , is there a CPS API for saving the entire solution, if it's dirty, presumably on IProjectService?
I have a scenario where, for unknown reasons, the usage of IVsSolution.SaveSolutionElement is giving me a bad HRESULT.
Oscar Salazar
@osqui2097
Hi, I need to add my CPS Project System as reference (this project generates a dll based on .Net Framework when it compiles) in a C# project, how can I do that?
jp2masa
@jp2masa
does the project system import the common targets?
Oscar Salazar
@osqui2097
@jp2masa which common targets?
jp2masa
@jp2masa
Microsoft.Common.CurrentVersion.targets
Oscar Salazar
@osqui2097
But if I import those common targets in my project configuration file, I can't compile the files added in the project, so what can I do in this case? @jp2masa
jp2masa
@jp2masa
fix your targets, or manually add the targets needed to implement the project reference protocol and design time contracts
Oscar Salazar
@osqui2097
Ok, thank you @jp2masa
Rishabh Verma
@Rishabh-V
Hi Folks! I am facing a strange issue.
I have migrated a solution from .NET Core 1.0 to .NET Core 1.1 (so projects changed from xproj to csproj). When I add a new project from Visual Studio, it works fine. However, if I copy paste an already migrated project, rename it and try to add it to the solution it shows the upgrade dialog, though its already upgraded and is csproj.
The issue I identified is that in sln file it adds a wrong guid for project type, which if I change, it starts working. Just curious to know whats going on so any insights would be very helpful. How does VS determine the guid that it appends in sln file? Thanks.
Kirk Fertitta
@kfertitta

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?

Oscar Salazar
@osqui2097
@jp2masa I tried to do what you told me, but it doesn't run, which targets I need to fix?
Kirk Fertitta
@kfertitta

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.

image.png
jp2masa
@jp2masa
@osqui2097 the easiest way would be importing the common targets, you can override the values which cause problems...
@kfertitta the PackageReferences capability is for projects which support PackageReferences 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
Kirk Fertitta
@kfertitta

@jp2masa Oh, wow. I was poking around those issues and thought I hit a dead end because most references lead to this:

dotnet/project-system#2491

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.

Kirk Fertitta
@kfertitta

@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.

jp2masa
@jp2masa
there are some capabilities which have to be defined, let me check
Kirk Fertitta
@kfertitta
Thanks @jp2masa . Adding those three capabilities at the top of that link made it all work.
Oscar Salazar
@osqui2097
It worked, thank you @jp2masa
Kirk Fertitta
@kfertitta
@jp2masa I have a NuGet for my custom project system build tools, and I can install it via the Visual Studio Package Manager, but it always uses the packages.config style instead of PackageReference.
It generates the packages.config and adds it to the project, and downloads the package to a solution-level packages folder.
I have PackageReference selected in Tools -> Options as the default and I'm even setting the RestoreProjectStyle property in my project file to PackageReference.
Also, even though it is using 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.
When I install the very same NuGet into a C# project, a PackageReference is correctly generated.
When I install the very same NuGet into a C++ project, the 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 .
Also, the package does not show up under my Dependencies node in Solution Explorer.
jp2masa
@jp2masa
you shouldn't use packages.config, but no idea why the package manager is not using package references...
Kirk Fertitta
@kfertitta
Yeah, I don't want to use packages.config.
All I did was take the WindowsScript sample, add the capabilities needed to support NuGet, add the Xaml files for PackageReference and ResolvedPackageReference and that's the behavior your see.
It's identical between my actual project system and the sample with those changes.