-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best way to detect target framework(s) in a CPS project #430
Comments
But for what ever reasons, getting the nugets doesn't work for all users all time. |
They look too internal/wip to me. Hoping a more general solution from @reduckted perhaps? 😄 |
Microsoft has some plans to maybe publish them on nuget when a new VS 2022 update is released. As you can see this is a long open issue and it can still take some time to get it solved |
I ended up doing this: private static async Task<string> GetTargetFrameworkMonikersAsync(Project project)
{
string result = null;
project.GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out _);
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
try
{
var vsProject = (IVsProject)hierarchy;
if (vsProject != null)
{
var props = vsProject.ToProject().Properties;
result = props.Item("TargetFrameworkMonikers")?.Value?.ToString();
}
}
catch
{
// Ignore
}
if (string.IsNullOrEmpty(result))
{
result = await project.GetAttributeAsync("TargetFrameworkMoniker");
}
return result;
}
private static EnvDTE.Project ToProject(this IVsProject vsProject)
{
ThreadHelper.ThrowIfNotOnUIThread();
var vsHierarchy = (IVsHierarchy)vsProject;
var hr = vsHierarchy.GetProperty(
(uint)VSConstants.VSITEMID.Root,
(int)__VSHPROPID.VSHPROPID_ExtObject,
out var project);
Marshal.ThrowExceptionForHR(hr);
return (EnvDTE.Project)project;
} |
I tried:
await project.GetAttributeAsync("TargetFrameworkMoniker");
But it breaks with:
<TargetFrameworks>netstandard2.1;net6.0</TargetFrameworks>
(Only the first one is returned)
"TargetFrameworkMonikers" retrurns an empty string
The text was updated successfully, but these errors were encountered: