Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source files included with an absolute path ignored on Linux #108

Open
dmirmilshteyn opened this issue May 2, 2019 · 2 comments
Open

Source files included with an absolute path ignored on Linux #108

dmirmilshteyn opened this issue May 2, 2019 · 2 comments
Labels
⚠ Bug Something isn't working as expected

Comments

@dmirmilshteyn
Copy link

dmirmilshteyn commented May 2, 2019

I have a project which I analyze on both Windows and Linux, and it seems like some files are being excluded/ignored from the source files collection when running the analyses on Linux. It works fine with the same inputs on Windows.

Specifically, it seems like any files that have been included in the Compile item group with an absolute path are ignored on Linux.

Example: <Compile Include="$(MSBuildThisFileDirectory)Item.cs" />

There are two cases where I need to include files like this: a custom file outside the project directory, used with many projects, and shared projects.

VS adds all items in shared projects in that style. Apart from that, shared projects seem to work fine.

I believe this is happening because the Csc command line parser treats filepaths of the form "/path/to/item.cs" as an argument instead of a file path, but I'm really not sure.

Project:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="$(MSBuildThisFileDirectory)..\test.cs" />
  </ItemGroup>
</Project>

This file path resolves to /path/to/test.cs

Code used to analyze:

AnalyzerManager manager = new AnalyzerManager();
ProjectAnalyzer analyzer = manager.GetProject(@"/path/to/project.csproj");
AnalyzerResults results = analyzer.Build();
string[] sourceFiles = results.First().SourceFiles; // test.cs not included on Linux, but is on Windows

FullExampleProject.zip

Thanks!

@daveaglick daveaglick added the ⚠ Bug Something isn't working as expected label May 16, 2019
@daveaglick
Copy link
Collaborator

I released 2.3.0 this morning and it has a rewritten command line parser. Can you give it a try and report back?

@othmane-kinane-nw
Copy link

I'm using version 5.0.0 and I have a similar problem: files with absolute paths are not reported in Linux. These files are considered as options because of their leading /: https://github.com/daveaglick/Buildalyzer/blob/main/src/Buildalyzer/AnalyzerResult.cs#L229

My workaround is to transform all Compile item paths to relative paths with this target (see
https://github.com/nimbleways/dotnet-subset/blob/ede95798a/Directory.Build.targets#L7-L15):

  <!-- Workaround for https://github.com/daveaglick/Buildalyzer/issues/108 -->
  <Target Name="MakeCompileItemsRelative" BeforeTargets="CoreCompile">
    <ItemGroup>
      <CompileWithRelativePaths Include="@(Compile->'$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)', '%(Compile.Identity)'))')" />
      <Compile Remove="@(Compile)" />
      <Compile Include="@(CompileWithRelativePaths)" />
    </ItemGroup>
  </Target>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠ Bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

3 participants