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

Exclude is overzealous when exclude pattern is an absolute path prefix of include directory #2813

Closed
rla4 opened this issue Jan 11, 2019 · 8 comments

Comments

Projects
None yet
5 participants
@rla4
Copy link

commented Jan 11, 2019

When building an SDK project, the source files are not being collected correctly, causing a "CS5001: Program does not contain a static 'Main' method suitable for an entry point" error. If I change the OutputPath to anything other than a substring of the source path, all source files are picked up just fine and build succeeds. Issue only happens after the 2nd build (presumably because the output folder is not empty).

Still repro'ed on latest stable 2.2, but could not repro on 3.0.100-preview-009812, so possibly an issue that only affects < 3.0.

Repro steps:

mkdir C:\Temp2 && cd C:\Temp2
@echo {"sdk":{"version":"2.2.100"}}> global.json
mkdir TestFullPath && cd TestFullPath && dotnet new console && cd ..
dotnet build C:\Temp2\TestFullPath\TestFullPath.csproj -o C:\Temp2\Test
dotnet build C:\Temp2\TestFullPath\TestFullPath.csproj -o C:\Temp2\Test

Output:

C:\Temp2
λ cd ..

C:\
λ rm -rf C:\Temp2

C:\
λ mkdir C:\Temp2 && cd C:\Temp2

C:\Temp2
λ @echo {"sdk":{"version":"2.2.100"}}> global.json

C:\Temp2
λ mkdir TestFullPath && cd TestFullPath && dotnet new console && cd ..
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on C:\Temp2\TestFullPath\TestFullPath.csproj...
  Restoring packages for C:\Temp2\TestFullPath\TestFullPath.csproj...
  Generating MSBuild file C:\Temp2\TestFullPath\obj\TestFullPath.csproj.nuget.g.props.
  Generating MSBuild file C:\Temp2\TestFullPath\obj\TestFullPath.csproj.nuget.g.targets.
  Restore completed in 193.24 ms for C:\Temp2\TestFullPath\TestFullPath.csproj.

Restore succeeded.


C:\Temp2
λ dotnet build C:\Temp2\TestFullPath\TestFullPath.csproj -o C:\Temp2\Test
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 35.26 ms for C:\Temp2\TestFullPath\TestFullPath.csproj.
  TestFullPath -> C:\Temp2\Test\TestFullPath.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.06

C:\Temp2
λ dotnet build C:\Temp2\TestFullPath\TestFullPath.csproj -o C:\Temp2\Test
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 37.45 ms for C:\Temp2\TestFullPath\TestFullPath.csproj.
CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [C:\Temp2\TestFullPath\TestFullPath.csproj]

Build FAILED.

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [C:\Temp2\TestFullPath\TestFullPath.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.94
@NickCraver

This comment has been minimized.

Copy link
Member

commented Jan 11, 2019

cc @livarcocc - this is solved in 3.x but not 2.2.x latest stable, thoughts?

@livarcocc

This comment has been minimized.

Copy link
Member

commented Jan 11, 2019

Man, github is a small world, I actually went to school with @rla4, whether she remembers or not.

I am not sure exactly which change happened in 3.0 to fix this issue there. @peterhuene can you take a look? Depending on the change, we can try to do bar check and bring it the fix to 2.2 in a servicing release.

@livarcocc livarcocc added this to the 2.2.1xx milestone Jan 11, 2019

@peterhuene

This comment has been minimized.

Copy link
Member

commented Jan 11, 2019

iirc, there was a fix from the community related to output option handling that I think went into master. I'll try to dig it up.

@peterhuene

This comment has been minimized.

Copy link
Member

commented Jan 11, 2019

dotnet/cli#9892 was the PR I'm thinking of. That might have addressed this issue. I'll check.

@peterhuene

This comment has been minimized.

Copy link
Member

commented Jan 11, 2019

That wasn't what addressed the issue in 3.0, so now I'm bisecting.

@peterhuene peterhuene self-assigned this Jan 12, 2019

@peterhuene

This comment has been minimized.

Copy link
Member

commented Jan 14, 2019

I'm actually able to reproduce this in 3.0, both in master and preview 1:

mkdir foobar
cd foobar
dotnet new console
dotnet build -o ..\foo
dotnet build -o ..\foo

I can also reproduce it without modifying the output path and without default items enabled:

mkdir foo
mkdir foobar
cd foobar
dotnet new console

Edit foobar.csproj to:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <EnableDefaultItems>false</EnableDefaultItems>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**/*.cs" Exclude="c:\users\peter\foo/**/*" />
  </ItemGroup>

</Project>

Note: replace the full path in the exclude to be the same base bath where foobar resides (i.e. if foobar is in C:\baz then the Exclude should be C:\baz\foo/**/*.

If the Exclude glob is not absolute, it does not repro. If the excluded directory does not exist (e.g. c:\users\peter\foo), it does not repro. If the excluded directory is not a substring of the project directory (e.g. c:\users\peter\foo is a substring of c:\users\peter\foobar), it does not repro. If an additional backslash is placed between the directory to exclude and the glob (e.g. c:\users\peter\foo\/**/* or c:\users\peter\foo\**\*), it does still repro.

dotnet build would then reproduce the same error without having to modify the output path. No source files are being passed to the compiler because the items are being improperly excluded by MSBuild.

Pinging @rainersigwald in case he has additional information that might be useful.

@peterhuene peterhuene modified the milestones: 2.2.1xx, 3.0.1xx Jan 14, 2019

@peterhuene

This comment has been minimized.

Copy link
Member

commented Feb 12, 2019

@rainersigwald given the repro above in my comment that makes it appear the problem lies in how globs are handled in MSBuild, so I move the issue there?

@rainersigwald rainersigwald changed the title dotnet build fails when OutputPath starts with the source path Exclude is overzealous when exclude pattern is an absolute path prefix of include directory Feb 14, 2019

@rainersigwald

This comment has been minimized.

Copy link
Contributor

commented Feb 14, 2019

Great find! Moved to microsoft/msbuild#4175, with an even smaller repro. I understand the fix, too.

@peterhuene peterhuene closed this Feb 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.