dotnet / wcf

This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services.
MIT License
1.69k stars 556 forks source link

The dotnet-svcutil tool does not resolve the value of the TargetFramework property when it contains other MSBuild properties. #5427

Open RuneH-MSFT opened 4 months ago

RuneH-MSFT commented 4 months ago

Describe the bug When using the dotnet-svcutil tool from a C# SDK-style project and the project has <TargetFramework>$(LibTargetFramework)</TargetFramework>, the dotnet-svcutil tool will fail with a message about $(LibTargetFramework) not being a supported target framework even though the LibTargetFramework property resolves to netstandard2.0.

The target framework '$(libtargetframework)' is not a supported .NET Core, .NET Standard, or a .NET Framework version. The minimum supported framework versions are as follows: netcoreapp1.0, netstandard1.3 and net4.5.

The command "dotnet tool run dotnet-svcutil "WSDL\Repro.wsdl" -tf "netstandard2.0" -n "*,Repro.Proxy.Generated" -o ".generated\ReproProxy.cs" -v Verbose" exited with code 2.

I am using dotnet-svcutil 2.1.0 when encountering this error. If I change the TargetFramework property in the project file to be netstandard2.0 rather than using a property, it works.

To Reproduce Steps to reproduce the behavior:

  1. Create a C# SDK-style library project for .NET Standard 2.0.
  2. Add a Directory.Build.props file and defined a property: <LibTargetFramework>netstandard2.0</LibTargetFramework>
  3. Update the csproj to set: <TargetFramework>$(LibTargetFramework)</TargetFramework>
  4. Add a custom target to invoke the dotnet-svcutil tool before the Build target.

See attached TestDotNetSvcUtilLib_CSProj.zip.

Expected behavior The TargetFramework property should be resolved correctly.

imcarolwang commented 4 months ago

Thanks for raising the issue, @RuneH-MSFT. There are some bug fixes in the latest preview version of the tool, instead of using dotnet-svcutil 2.1.0, could you please give version 2.2.0-preview1.23462.5 a try?

RuneH-MSFT commented 4 months ago

@imcarolwang - That 2.2.0-preview1.23462.5 version from August does not appear to have the same issue. From searching other issues it looks like an issue was previously reported on this and was resolved in 2.0.1. Since I encounter it on 2.1.0, Hong Li requested that I log a new issue for this to make sure it is fixed in a non-preview release, so we can start using the tool. I hope there will be a non-preview release with the fix made available soon.

RuneH-MSFT commented 4 months ago

@imcarolwang - With the 2.2.0-preview1.23462.5 version I can get a bit further, but I run into another error also related to using a property as the target framework when the project has assembly references without a hint path like this:

  <ItemGroup>
    <Reference Include="System.ServiceModel" />
  </ItemGroup>

The dotnet-svcutil tool will fail with this error:

The project reference specification 'System.ServiceModel' does not have a file path.

The command "dotnet tool run dotnet-svcutil "WSDL\Repro.wsdl" -ntr -tf "net48" -n "*,Repro.Proxy.Generated" -o ".\Generated\ReproProxy.cs" -v Verbose" exited with code 2.

In this case I am using "net48" as the value of the LibTargetFramework property in Directory.Build.props. If I change the project to use "net48" directly as the value of the TargetFramework property, I do not get this error.

It seems like the same problem where it does not correctly resolve the TargetFramework value.

I have attached another repro project for this variation of the problem: TestDotNetSvcUtilLib_CSProj_2024-02-20.zip