In the context of a few tests I had the requirement to add the path of a native library, which is part of a nuget package, to the PATH environment variable. Here a code snippet how to detect a path and to add it:
string assemblyCodeBase = typeof(System.Data.SQLite.SQLiteConnection).Assembly.Location; string assemblyLocation = System.IO.Path.GetDirectoryName(new Uri(assemblyCodeBase).LocalPath); string envVarPath = System.Environment.GetEnvironmentVariable("PATH"); System.Environment.SetEnvironmentVariable("PATH", @assemblyLocation + ";"+ envVarPath);
With the typeof operator we get the type of the class, in the assembly whose path we require. We use Assembly.Codebase and from this result we get via Uri.LocalPath and GetDirectoryName the path name. Last but not least we add it to the PATH environment variable via SetEnvironmentVariable.
On this way it is possible to detect at runtime the path to an assembly, in this case is this a part of a Nuget package, and to add it to an environment variable.
Tried this approach with UiPath Studio 22.8 in Windows compatibility mode.