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

Cannot convert from 'Cake.Common.Tools.MSBuild.MSBuildSettings' to 'Cake.Common.Tools.DotNetBuildSettings' #849

Closed
bjorkstromm opened this issue Apr 28, 2016 · 11 comments
Labels

Comments

@bjorkstromm
Copy link
Member

bjorkstromm commented Apr 28, 2016

Steps to reproduce:

Task("Default")
    .Does(() => 
{
    new MSBuildSettings()
        .WithProperty("foobar", MakeAbsolute(Directory(".")));

});

This will output error message:

error CS1929: Instance argument: cannot convert from 'Cake.Common.Tools.MSBuild.MSBuildSettings' to 'Cake.Common.Tools.DotNetBuildSettings'

Workaround add ToString()

Task("Default")
    .Does(() => 
{
    new MSBuildSettings()
        .WithProperty("foobar", MakeAbsolute(Directory(".")).ToString());

});
@devlead
Copy link
Member

devlead commented Apr 28, 2016

WithPropery takes string/strings as value parameter, you're passing a FilePath to it.
MakeAbsolute(..).FullPath should work too.

Could be some implicit thing that happens when wrong type is supplied.

@bjorkstromm
Copy link
Member Author

Yep, for some reason the compiler want's to use the DotNetBuildSettings extension instead.

I though the MakeAbsolute alias returned a ConvertableDirectoryPath/ConvertableFIlePath, hence the no string conversion. But after checking source, I was wrong 😄

@devlead
Copy link
Member

devlead commented Apr 28, 2016

@mholo65 you could try launching cake.exe with the -Experimental flag which will launch a newer version of Roslyn, might be an issue that's sorted, if it's an compiler issue.

@bjorkstromm
Copy link
Member Author

@devlead Same error, slightly different error message:

error CS1929: 'MSBuildSettings' does not contain a definition for 'WithProperty' and the best 
extension method overload 'DotNetBuildSettingsExtensions.WithProperty(DotNetBuildSettings, 
string, params string[])' requires a receiver of type 'DotNetBuildSettings'

I would however call this an compiler issue. It may be solved by moving DotNetBuildSettings (and aliases) to another namespace than Cake.Common.Tools

@bjorkstromm
Copy link
Member Author

Same issue with XBuild. But when switching to DotNetBuild, the compiler gives correct error message:

error CS1503: Argument 3: cannot convert from 'Cake.Core.IO.DirectoryPath' to 'string'

@patriksvensson
Copy link
Member

@mholo65 Excellent finding this. If you have time, could you check if your theory about moving DotNetBuild to another namespace would solve the problem?

@bjorkstromm
Copy link
Member Author

@patriksvensson np. So I tried moving to namespace Cake.Common.Tools.DotNet still same issue. Which makes sense in a way, because that namespace is loaded before Cake.Common.Tools.MSBuild/Cake.Common.Tools.XBuild in cake-script. If moving to namespace Cake.Common.Tools.ZotNet I'll get the correct error for MSBuild

error CS1503: Argument 3: cannot convert from 'Cake.Core.IO.DirectoryPath' to 'string'

But then again XBuild reports

error CS1929: Instance argument: cannot convert from 'Cake.Common.Tools.XBuild.XBuildSettings' to 'Cake.Common.Tools.MSBuild.MSBuildSettings'

Becouse the MSBuild namespace is loaded before XBuild.

Now if I add an extension method public static CakeSettings WithProperty(this CakeSettings settings, string name, params string[] values) to CakeSettings, I'll get the error message:

error CS1929: Instance argument: cannot convert from 'Cake.Common.Tools.MSBuild.MSBuildSettings' to 'Cake.Common.Tools.Cake.CakeSettings'

Soo, the bottom line is: We are importing unnecessary namespaces. Might be difficult to fix, would still say that this is an Compiler issue (finding other methods with same name but slightly different signature and trying to implicitly cast.). Root cause is user error (trying to cast DirectoryPath/FilePath to string), but It would be great to get the correct error message.

The MSBuild/XBuild/DotNetBuild could be easy to fix using inheritance though.

@daveaglick
Copy link
Member

FYI, just hit this so problem still exists in 0.23.0

@bjorkstromm
Copy link
Member Author

I think we was ready to remove DotNetBuild aliases soon, that is the ultimate fix 😄

@daveaglick
Copy link
Member

That'll do it 😄

@bjorkstromm
Copy link
Member Author

DotNetBuild was obsoletet here #1796 and will be removed with this issue #2292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants