opentelemetry-dotnet icon indicating copy to clipboard operation
opentelemetry-dotnet copied to clipboard

:beer: I'm in a love/hate relationship with VSCode :beer:

Open alanwest opened this issue 3 years ago • 2 comments

There have been some substantial improvements recently to the development experience in VSCode for the opentelemetry-dotnet project (#2997 and #3036).

Though even after #3036, I still have issues running tests in some (but not all) projects. For example, tests now run fine for the OpenTelemetry.Tests project but not for OpenTelemetry.Exporter.OpenTelemetryProtocol project.

VSCode's test runner expects build output to be in the opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/bin/Debug/net6.0/ref directory. Apparently, with .NET SDK 6.0.200+ build output is no longer copied to the ref directory. #3036 fixed this, but only for some projects.

To repro:

You know that little Run Test button above each test in VSCode? Clicking that button on a test in the OpenTelemetry.Test project works just fine. However, clicking that button on a test in the OpenTelemetry.Exporter.OpenTelemetryProtocolTests project like this one here does not work fine:

Screen Shot 2022-04-29 at 3 33 04 PM

Clicking Run Test builds the project and results in the same error I experienced from #3036.

Build FAILED.

/usr/local/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(4650,5): error MSB3883: Unexpected exception:  [/Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj]
/usr/local/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(4650,5): error : DirectoryNotFoundException: Could not find a part of the path '/Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/bin/Debug/net6.0/ref/OpenTelemetry.Exporter.OpenTelemetryProtocol.dll'. [/Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj]
/usr/local/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj]
/usr/local/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Interop.CheckIo(Error error, String path, Boolean isDirectory, Func`2 errorRewriter) [/Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj]
/usr/local/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj]
/usr/local/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [/Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj]
/usr/local/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj]
/usr/local/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Copy() [/Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj]
/usr/local/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(4650,5): error :  [/Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj]
    0 Warning(s)
    2 Error(s)

Seriously... I will buy a 🍺 for the first person who can figure this nonsense out.

alanwest avatar Apr 29 '22 23:04 alanwest

The error is saying it cant find /Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/bin/Debug/net6.0/ref/OpenTelemetry.Exporter.OpenTelemetryProtocol.dll

To me it looks like its missing something like c:\ or if on Mac or Linux then like /home/?? It could be an issue with the test runner but looks like a code analyser problem?

p10tyr avatar May 16 '22 20:05 p10tyr

The error is saying it cant find /Users/awest/github/open-telemetry/opentelemetry-dotnet/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/bin/Debug/net6.0/ref/OpenTelemetry.Exporter.OpenTelemetryProtocol.dll

Correct, the built binaries (e.g., OpenTelemetry.Exporter.OpenTelemetryProtocol.dll) are located one directory up from the ref directory, but the VSCode test runner expects to find them under ref. In previous versions of the .NET 6.0 SDK the binaries were copied to the ref directory. This is a known breaking change to the SDK https://docs.microsoft.com/en-us/dotnet/core/compatibility/sdk/6.0/write-reference-assemblies-to-obj.

The workaround is to set the ProduceReferenceAssemblyInOutDir MSBuild property as I've done here: https://github.com/open-telemetry/opentelemetry-dotnet/blob/55c5dd18e9bcb8f9f728aa1a0557bd5157c88362/build/Common.nonprod.props#L22-L26

The change should cause the binaries to be copied to the ref directory which makes the test runner happy. And it does for some projects... but not all. This is the thing I haven't been able to figure out. The Common.nonprod.props should be incorporated into every csproj file under the root test directory of the opentelemetry-dotnet repo.

alanwest avatar May 17 '22 19:05 alanwest

I have been able to debug tests successfully in VSCode recently. I guess something with VSCode was fixed? I plan to pour myself a 🍺.

alanwest avatar Aug 30 '22 22:08 alanwest