How SmartAssembly searches for dependencies
Published 31 December 2012
Default dependency search order
To locate and load a dependency, SmartAssembly searches for the dependency in the specific locations, depending on the application type, exactly in the order provided below.
As a rule of thumb, if the selected main application runs correctly from within the input directory, then SmartAssembly should be able to locate all of its dependencies.
.NET Core / .NET Standard
- Servicing paths.
- The main assembly folder.
- .NET Core runtime folders (based on .deps.json and .runtimeconfig.json files).
- Shared store paths (as indicated by
DOTNET_SHARED_STOREenvironment variable or default global shared stores).
- Additional probing paths (as indicated by .runtimeconfig.json and .runtimeconfig.dev.json).
- Default system-wide and user-wide NuGet folders when .runtimeconfig.json file is invalid or missing.
- The GAC (Global Assembly Cache) — only when the assembly is missing its configuration files (.deps.json, .runtimeconfig.json, .runtimeconfig.dev.json) and the dependencies weren't found in the assembly's directory.
.NET Framework and other frameworks
- The GAC (Global Assembly Cache). The dependency must have an assembly name which includes the same version number and public key token.
- The main assembly folder for a dependency with a similar assembly name.
- The framework core assemblies directories.
- The framework folder and associated folders (for SDKs, XNA, etc.).
Modifying the search order
If your dependency is not found, or if the wrong version of it is found, you can override the normal searching behavior.
You can force SmartAssembly to use a particular assembly file by manually editing the SmartAssembly project file (*.saproj) in an XML editor. To do this, add the
MandatoryPath attribute to the
Assembly> tag, as in the example below:
<Assembly AssemblyName="dependency_assembly_name" MandatoryPath="C:\path\DependencyToUse.dll"> ... </Assembly>
SmartAssembly will always use the dependency found at this location. Default search order is never executed when
MandatoryPath is used.
If the dependency is not valid (for example, the file is not found, or the assembly has a different assembly name), SmartAssembly does not process your assembly and reports an error.
You can instruct SmartAssembly to use a particular assembly file by manually editing the SmartAssembly project file (*.saproj) in an XML editor. To do this, add the
HintPath attribute to the
Assembly> tag, as in the example below:
<Assembly AssemblyName="dependency_assembly_name" HintPath="C:\path\DependencyToUse.dll"> ... </Assembly>
If the assembly is invalid, or the assembly file doesn't exist, dependency search will continue with a default search order.
You can set additional directories where SmartAssembly will look for dependencies by manually editing the SmartAssembly project file (*.saproj) in an XML editor. To do this, add the
<HintPaths> tag inside the
Configuration> tag and fill it with any number of
<Directory> tags, as shown in the example below:
<SmartAssemblyProject ...> <Configuration Name="Release"> <HintPaths> <Directory>C:\Additional\Search\Path\For\Project\</Directory> </HintPaths> <Assemblies> ... </Assemblies> </Configuration> ... </SmartAssemblyProject>
Removing folders from the dependency search
In rare cases, you may wish to ignore a folder when SmartAssembly searches for a dependency. An example is when you do not have permission to access the folder, and so you cannot check which versions of the dependency are in the folder.
This only applies to folders already added to the dependency search list by clicking Add a new search folder on a Dependency Not Found dialog.
To remove a folder from the dependency search:
- In an XML editor, open the %ProgramData%\Red Gate\SmartAssembly 7\SmartAssembly.settings file.
- Find the
- In the
DependenciesSearchPaths>, each search path is contained in a
- Delete the search path that you do not want to look in when SmartAssembly searches for dependencies.