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