How to not add references with absolute path and make use of SearchPaths

Using the Studio demo app, if I add my custom control to the Form Designer surface, the references to the assembly containing my custom control and dependent assemblies get automatically added to the reference list. The added references, however, are using absolute paths.

This creates exceptions when running the same code on different devices as they have different paths to the custom control assemblies.

How can I get Form Designer to add the references using just the names and add search paths so that they can be found both during design time and run time.

Thanks.

I tried to reproduce the issue and did the following:

  • Opened the AlterNET Studio for Windows Forms sample
  • In the project opened by default, double-clicked on the Form1.cs node in the Project Explorer tree to open the form designer
  • In the Toolbox tab, right-clicked the toolbox and chose “Add Library”. In the opened file dialog I selected the custom control library I prepared for this test
  • My custom control appeared on the toolbox. I dragged it onto the design surface. The control appeared there.
  • After that I chose the File/Save Project menu item
  • Looking at what has changed in the project file, I found the following:
<Reference Include="..\..\..\..\..\..\..\Temp\AS\MyCustomControl\MyCustomControl\bin\Debug\MyCustomControl.dll" />

As you can see, a relative path is getting saved to the project, not the absolute one.

If your scenario and its outcome are different, please specify the steps required to reproduce this.

Thanks Yevgeni for your response.

  1. If the custom control assemblies are located on a different drive from the startup location of the demo app, then absolute paths will be used
  2. In either cases, my objective is to have the reference specifies only the assembly name. Like “System”. And tell the resolver to search for the assemblies in a set of search paths. Is this possible?

Hope that helps.

Hi Michael,

We looked at this scenario, and it seems that we have most of the functionality here to add assembly references by name without a full path (absolute or relative).

When a user adds a third-party component to the Designer, we resolve all references and add them to the DesignerReferencedAssemblies.References collection. DesignerReferencedAssemblies already has property SearchPaths, so we can ignore the full path if these references are located in one of these directories. It will require minor changes in our source code, but these changes are relatively straightforward.

Similarly, we can use these SearchPaths with the Scripter (the ScriptRun.ScriptSource.SearchPaths property) and with the Editor (RoslynSolution.AssemblySearchPaths property); or resolve full paths when adding references from the Designer to the Scripter/Editor like it is working now.

The question here is how these SearchPaths will be set in the Designer. In our FormDesigner demo, we load a single form and additional information associated with the assembly references from the .DesignerSettings.xml file. We can certainly extend this file to store SearchPaths information. With the AlterNET Studio demo, however, we load the .csproj or .vbproj project file, which we might need to extend with a custom tag to store these assembly Search Paths.

Please let us know if you will use a project file or a single form in the Designer, and we will prepare changes in our code and demo projects required to make references work without full paths.

Kind regards,
Dmitry

Hi Dmitry,

I think there is no need to save the search paths as the goal is to provide them dynamically.

We can set the search paths just before project load. Please also consider using the path of the current executing assembly, the GAC, and etc… as default.

Will probably be helpful to have a “Reference Resolving” event fired when the project is loading so that the developer can response to the event and construct/modify the search paths.

Thanks and regards
Michael

Hi Michael,

We will add reference resolving so if a global search path is provided, and added reference is found there, it will add an assembly name also. We will provide an event as well, and update our demo projects to show how this can be done.

We’re going to include this change in the next NuGet update, which we’re going to release next week. I will keep you posted.

Kind regards,
Dmitry

Hi Dmitry,

I see that this has been released in 8.1.7. Can you please forward me the download links to the updated source and demo.

Thank you and regards
Michael

Hi Michael,

We have released another minor update to NuGet, version 8.1.8, and just updated our demos on GitHub:

We have changed the logic of our reference resolver, which now looks at the provided search paths, and uses the assembly name without a path in case a reference is found there.

Please take a look at the globalReferencePaths field in AlterNET Studio and FormDesigner demo projects and let us know if this is what you’re looking for.

I will send you a link to the sources by email.

Kind regards,
Dmitry