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

Microsoft.AspNetCore.Mvc.Testing failed to build with error MSB4186 #42772

Closed
1 task done
ascentis-kelvingo opened this issue Jul 18, 2022 · 3 comments · Fixed by #42863
Closed
1 task done

Microsoft.AspNetCore.Mvc.Testing failed to build with error MSB4186 #42772

ascentis-kelvingo opened this issue Jul 18, 2022 · 3 comments · Fixed by #42863
Assignees
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-mvc-testing MVC testing package investigate

Comments

@ascentis-kelvingo
Copy link

ascentis-kelvingo commented Jul 18, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Having issue with the latest Microsoft.AspNetCore.Mvc.Testing with version 6.0.7 in the integration tests project.

This is my project structure.
image

This is the .csproj of the integration tests project.
image

I'm getting the MSB4186 error when I tried to build the integration tests project, I'm able to run the web app project directly without issue but not the integration test project.
image

4>C:\xxx\.nuget\packages\microsoft.aspnetcore.mvc.testing\6.0.7\build\net6.0\Microsoft.AspNetCore.Mvc.Testing.targets(34,9): error MSB4186: Invalid static method invocation syntax: "[System.IO.Path]::GetDirectoryName(C:\xxx\src\Template.Project.Core\Template.Project.Core.csproj)". Method 'System.IO.Path.GetDirectoryName' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)). Check that all parameters are defined, are of the correct type, and are specified in the right order.

According to #31066, I tried to remove the condition in the targets but the project still failed to build.

Expected Behavior

The project is built successfully.

Steps To Reproduce

  1. Create a net6.0 class library with the name Template.Project.Core.
  2. Create a net6.0 class library with the name Template.Project.Infrastructure.
  3. Create a net6.0 ASP.Net Core Web App (MVC) with the name Template.Project.WebApp.
  4. Create a net6.0 NUnit Test Project with the name Template.Project.IntegrationTests.
  5. Follow the instruction in https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-6.0#aspnet-core-integration-tests.
  6. Build the integration tests project.
UPDATE 1

Rename the parent level folder to include ), the issue occurs when the full path contains ).

Exceptions (if any)

No response

.NET Version

6.0.302

Anything else?

No response

@ascentis-kelvingo
Copy link
Author

ascentis-kelvingo commented Jul 18, 2022

Update 1

Able to figure out the issue after trying for a few hours, the issue occurs because the full directory contains bracket ( & ). Proposing to add single quote wrap on this method in the targets file.

    <ItemGroup Condition="'@(_ContentRootProjectReferences->Count())' != 0">
      <_ManifestProjects Include="%(_ContentRootProjectReferences.FusionName)">
        <ContentRoot>$([System.IO.Path]::GetDirectoryName('%(_ContentRootProjectReferences.MSBuildSourceProjectFile)'))</ContentRoot>
      </_ManifestProjects>
    </ItemGroup>

Added single quote ' inside the GetDirectoryName method.

@javiercn javiercn added feature-mvc-testing MVC testing package area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Jul 18, 2022
@rafikiassumani-msft rafikiassumani-msft added this to the .NET 7 Planning milestone Jul 19, 2022
@ghost
Copy link

ghost commented Jul 19, 2022

Thanks for contacting us.
We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@brunolins16 brunolins16 self-assigned this Jul 20, 2022
@brunolins16
Copy link
Member

Update 1

Able to figure out the issue after trying for a few hours, the issue occurs because the full directory contains bracket ( & ). Proposing to add single quote wrap on this method in the targets file.

    <ItemGroup Condition="'@(_ContentRootProjectReferences->Count())' != 0">
      <_ManifestProjects Include="%(_ContentRootProjectReferences.FusionName)">
        <ContentRoot>$([System.IO.Path]::GetDirectoryName('%(_ContentRootProjectReferences.MSBuildSourceProjectFile)'))</ContentRoot>
      </_ManifestProjects>
    </ItemGroup>

Added single quote ' inside the GetDirectoryName method.

I think the proposed change make sense and I will open a PR soon, however, I am not sure why, but I was not able to repro the problem, even including the brackets.

image

@ghost ghost locked as resolved and limited conversation to collaborators Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-mvc-testing MVC testing package investigate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants