The IoT Core application I'm working on needs to know the (package) version of another application.
Is it possible to find out the version of another app (without needing the admin password as in the example below)?
Unfortunately AppDiagnosticInfo doesn't provide this information (it provides package family name).
I know this is possible with Device Portal REST api, but this requires the device admin password which is not suitable for production scenarios.
//Import WindowsDevicePortalWrapper with NuGet
using Windows.System.Diagnostics.DevicePortal;
(...)
var devicePortalConnection1 = new DefaultDevicePortalConnection(
"http://127.0.0.1:8080",
"administrator",
"my device administrator password");
var portal = new DevicePortal(devicePortalConnection1);
var packages = await portal.GetInstalledAppPackagesAsync();
You can use PackageManager to get the installed packages version. It does not need username and password,but it runs on device locally.
Please refer to below code.
Windows.Management.Deployment.PackageManager packageManager = new Windows.Management.Deployment.PackageManager();
IEnumerable<Windows.ApplicationModel.Package> packages = (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackages();
foreach(var pkg in packages)
{
var version = pkg.Id.Version;
Debug.WriteLine(string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision));
}
To run above code, you also need to add a restricted capability to the Package.appxmanifest. Had to add a new namespace at the top of the file:
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
and add the following to the Capabilties tag.
<rescap:Capability Name="packageQuery" />
You may need to add the 'rescap' namespace to the Ignorable list as per this information.
Related
In my project I am using NLog assembly with file version 4.6.6. My application is being loaded by the external app (no access to the source code) which also uses NLog with file version 4.7.2.
Everything from the external app and my app is being logged correctly. The strange thing that I am facing is that in my app I add the logging rules:
var uniqueLogName = "mylogger" + Guid.NewGuid();
var rule = new LoggingRule(uniqueLogName, ConvertLogLevel(SelectedLogLevel), myFileTarget);
LogConfig.LoggingRules.Add(rule);
var uniqueObjectsLogName = "myObjectslogger" + Guid.NewGuid();
var objectsRule = new LoggingRule(uniqueObjectsLogName, ConvertLogLevel(SelectedLogLevel), myObjectTarget);
LogConfig.LoggingRules.Add(objectsRule);
And for some reason I am getting folders with these rule names created on C drive (see the link below) and honestly, I don't even know where to look for the issue. Can this be some sort of configuration on the NLog?
I am trying to verify users with a JWT token. The code I used below works perfectly fine in a console application. But when I want to apply it in my Azure function it gives me the error:
Could not load file or assembly Microsoft.IdentityModel.Tokens
I do have one other Azure function in my solution but it doesn't use this NuGet package. I already took a look at this link:
Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=5.2.0.0
I can't get anything out of that. So what am I doing wrong? Thanks in advance
string key = "";
var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
var credentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);
var header = new JwtHeader(credentials);
var payload = new JwtPayload
{
{ "some ", "hello "},
{ "scope", "http://dummy.com/"},
};
var secToken = new JwtSecurityToken(header, payload);
var handler = new JwtSecurityTokenHandler();
var tokenString = handler.WriteToken(secToken);
var token = handler.ReadJwtToken(tokenString);
log.LogInformation(token.ToString());
Solved it by adding a line of code in the .csproj file
<PropertyGroup>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
I had this problem not when running in development, but on deployed projects. This did not relate to Azure project, but to a web application deployed onto a remote windows web server
I took these steps to resolve it:
Get the files names of the DLLs from references
Find these DLLS in the packages subfolder of your vs project.
Make sure you have the right version for your .net framework version
Copy the DLLs to a folder, we called it "deployments"
Remove the Nuget packages
Reference the DLLs directly with copylocal=true
You may or may not need to add the DLLs to the bin folder in your deployment package. The packages we needed are shown below
As part of trying to test a NuGet package with a Console application, is it possible to have the console application get the latest version of said NuGet package programmatically, and then use said package to call various methods and what not? This is the flow that I'm trying to achieve...
A NuGet package is created locally (already done as part of a build process)
A console application installs this package
The same console application calls a few methods that are inside this package (if this uses reflection insdie the console app to achieve this it isn't an issue)
How can this be achieved? I've tried the following code using the NuGet.Core & NuGet.Protocol NuGet packages...
// exception thrown for trying to resolving newtonsoft
IPackageRepository packageRepository = new NuGet.LocalPackageRepository(directoryPath);
PackageManager pm = new PackageManager(packageRepository, GetExecutingAssemblyDirectory());
pm.InstallPackage("package_id", SemanticVersion.Parse("package_version"));
NuGet.Common.ILogger logger = new Logger();
IEnumerable<LocalPackageInfo> packageInfos = LocalFolderUtility.GetPackagesV2(directoryPath, logger);
foreach (LocalPackageInfo lpi in packageInfos)
{
// no obvious way to actually install the package
}
// never more than zero packages
var localRepo = new LocalPackageRepository(directoryPath);
var packages = localRepo.GetPackages();
if (packages?.Count() > 0)
{
var packageManager = new PackageManager(localRepo, GetExecutingAssemblyDirectory());
packageManager.InstallPackage(packages.ElementAt(0).Id);
}
I haven't been able to get any of those pieces of code to work. Is this actually possible? Would I have to look at using 2 Console apps (one to install into the other, which then does the calling of methods), and if so how would this be done?
I'm trying to write an application that communicates with Visual Studio Team Services, using the Nuget packages listed here.
The example code is directly from Microsoft's official documentation, on same same page the packages are listed, under "Pattern for use". My test code is in a console application, set to version 4.7 of the .net framework (compiled by Visual Studio 2017 15.2(26430.16) Release, but I don't think that matters). The code is identical to Microsoft's example, other than changing the connection url, project, and repo name.
The only Nuget package directly installed (about 30 others are installed as dependencies) is Microsoft.TeamFoundationServer.ExtendedClient.
Install-Package Microsoft.TeamFoundationServer.ExtendedClient
using System;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.WebApi;
namespace vssApiTest
{
class Program
{
const String c_collectionUri = "https://[[redacted]].visualstudio.com/DefaultCollection";
const String c_projectName = "Inspections";
const String c_repoName = "Src";
static void Main(string[] args)
{
// Interactively ask the user for credentials, caching them so the user isn't constantly prompted
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
// Connect to VSTS
VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);
// Get a GitHttpClient to talk to the Git endpoints
GitHttpClient gitClient = connection.GetClient<GitHttpClient>();
// Get data about a specific repository
var repo = gitClient.GetRepositoryAsync(c_projectName, c_repoName).Result;
}
}
}
On the line VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);, a TypeLoadException is thrown (at run-time) with the message:
Inheritance security rules violated by type:
'System.Net.Http.WebRequestHandler'. Derived types must either match
the security accessibility of the base type or be less accessible.
None of the Google search variants I've tried on this error message have returned anything helpful.
Am I doing something wrong, is the example code I'm following wrong, or is there some other issue going on?
The problem was due to a bug introduced in version 4.1.0 of the System.Net.Http Nuget package, as discussed here.
The solution was to update that Nuget package to the latest version (4.3.2 at this time, it may have been fixed in earlier versions also).
i am able to create project/delete/rename everything but when it come for getting group its says "API resource location ebbe6af8-0b91-4c13-8cf1-777c14858188 is not registered on http://khanamar3:8080/tfs/DefaultCollection/" please help.....
public PagedGraphGroups GetAllGroups()
{
VssConnection connection = Context.Connection;
GraphHttpClient graphClient = connection.GetClient<GraphHttpClient>();
//error coming in next line...
PagedGraphGroups groups = graphClient.GetGroupsAsync().Result;
foreach (var group in groups.GraphGroups)
{
LogGroup(group);
}
return groups;
}
There might be two problems with
API resource location {0} is not registered on {1}
1. With URL
I think it should be without default collection, so in your example
http://khanamar3:8080/tfs/
2. With TFS/API version (I had this problem myself)
2.1
First check the version of your TFS server in TFS Management
for example
C:\Program Files\Microsoft Team Foundation Server 2018\Tools\TfsMgmt.exe
Once you know your TFS Server version you can see which API Version it supports
https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=vsts-rest-tfs-4.1
For example TFS 2018 UPDATE 1 supports API version 4.0
2.2
Then check what API version is called by DLLs you use. I coudn't find this information on nuget site
https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client/
UPDATE: You can check which dll version supports which TFS version here:
https://learn.microsoft.com/en-us/azure/devops/integrate/concepts/dotnet-client-libraries?view=azure-devops
but as described here
How to specify the API version?
you can check what API version is passed by the method using ILSpy
Method in your case would be:
GetGroupsAsync
And you can check this using https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.ILSpy
In my case it looked like this
So API from nuget Versioned 16.153.0 uses calls with 5.1.1
So in my case TFS 2018 UPDATE 1 did not supported API version 5.1.1, so I will need to downgrade nuget or upgrade TFS Server Version (or both)
You could use IIdentityManagementService with ListApplicationGroups to get the list of application groups.
TeamFoundationIdentity[] ListApplicationGroups(
string scopeId,
ReadIdentityOptions readOptions
)
Sample code
var applicationGroups = identityManagementService.ListApplicationGroups(projectcollection.Uri.AbsoluteUri, ReadIdentityOptions.None);
Also take a look at this similar question: TFS 2013 get All TFS group including Windows group