Samples icon indicating copy to clipboard operation
Samples copied to clipboard

Build fails if path contains # symbol

Open phizch opened this issue 3 years ago • 2 comments

I tried following the steps in the VSIX cookbook, but I got a build error:

CreatePkgDef : error : 
  ProvideCodeBaseAttribute: Could not load specified assembly: 'Community.VisualStudio.Toolkit' 
  reason: Could not load file or assembly 'file:///C:\Dev\Phizch\Community.VisualStudio.Toolkit.dll' or one of its dependencies.
  The system cannot find the file specified.

It took me several hours, but I finally tracked down the cause: My solution path.

C:\Dev\Phizch\C#\Visual Studio\InsertGuid

It worked without a problem when I moved the solution to:

C:\Dev\Phizch\Csharp\Visual Studio\InsertGuid

How to reproduce:

Clone this repsoitory into a folder whose path contains # Try to compile the InsertGuid project.

Start a Developer Command Prompt for VS 2022 Preview and run the following commands

cd \
md Test#
cd Test#
git clone https://github.com/VsixCommunity/Samples.git
cd Samples
devenv Samples.sln /Build Debug

Cause:

I'm not sure which org/repository the bug resides in, but I stumbled across it while trying to follow the tutorial for this sample. Anyway, I know what the bug is. Just not where it is.

Someone did this: new Uri( "file:///" + projectObjPath );¹ instead of new Uri( new Uri( "file:///" ), projectObjPath);. This results in practically the same incorrect uri as in the error message above.

file:///C:/Dev/Phizch/Community.VisualStudio.Toolkit.dll

The only difference is that the directory separator is \ in the error and / from ¹.

Fix:

Use Uri( Uri baseUri, string? relativeUri) constructor.

Workaround

Not use # in anywhere in the path. C:\Dev\Phizch\C#\ would be nice, and has worked for me so far, but I can live with Csharp.

phizch avatar Dec 09 '22 06:12 phizch

I found the source of the problem: ProvideDependentAssemblyAttribute gets the Assembly path from Assembly.CodeBase instead of Assembly.EscapedCodeBase. If anyone knows where I should report the bug, let me know.

CodeBase is functionally identical to "file:///" + path, while EscapedCodeBase is functionally identical to new Uri( new Uri( "file:///" ), path ).AbsoluteUri. Both would work fine for most paths, but if it contains a special character such as #, CodeBase won't work.

phizch avatar Dec 10 '22 05:12 phizch

I've made an issue in the microsoft/VSExtensibility repository. https://github.com/microsoft/VSExtensibility/issues/159

phizch avatar Dec 11 '22 08:12 phizch