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

[question] Conan 2.x Migration - MSBuild project properties #17847

Open
1 task done
radonish opened this issue Feb 25, 2025 · 1 comment
Open
1 task done

[question] Conan 2.x Migration - MSBuild project properties #17847

radonish opened this issue Feb 25, 2025 · 1 comment
Assignees

Comments

@radonish
Copy link

radonish commented Feb 25, 2025

What is your question?

Hello,
I'm working on migrating an MSBuild project to Conan 2.x that passed a "Platforms" property in Conan 1.x by doing something like:

def build(self):
    msbuild = MSBuild(self)
    build_properties = {"Platform":"Mixed Platforms"}
    msbuild.build("project.sln", parallel=False, use_env=False, properties=build_properties)

That affected the build configuration and the build would output:
Building solution configuration "Release|Mixed Platforms".

For Conan 2.x it looked like the equivalent would be to do the following:

def generate(self):
        tc = MSBuildToolchain(self)
        tc.properties["Platform"] = "Mixed Platforms"
        tc.generate()

        # If there are requirements
        deps = MSBuildDeps(self)
        deps.generate()

def build(self):
    msbuild = MSBuild(self)
    msbuild.build(sln=os.path.join(self.export_sources_folder, "project.sln"))

However, the build configuration is not as desired ("Release|Mixed Platforms") based on the output:
Building solution configuration "Release|x86".

Is there something I'm missing in my approach to get the "Platform" property down to MSBuild properly?

Thank you!

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@radonish radonish changed the title [question] Conan 2.x Migration - MSBuild project [question] Conan 2.x Migration - MSBuild project properties Feb 25, 2025
@memsharded memsharded self-assigned this Feb 25, 2025
@memsharded
Copy link
Member

Hi @radonish

Thanks for your question.

tc.properties["Platform"] = "Mixed Platforms"

The properties is only for generic key=value properties in the generate .props file, but not for changing the core platform.

The MSBuild helper has the .platform to define the desired command line argument:

cmd = 'msbuild "%s" /p:Configuration="%s" /p:Platform=%s' % (sln, self.build_type, self.platform)

# so 
build = MSBuild(self)
build.platform= "potato"
# will generate
msbuild ... /p:Platform=potato

If that is what you want.

A different thing is if using the conan_toolchain.props, because at the moment the conditions generated are:

    def _name_condition(self, settings):
        props = [("Configuration", self.configuration),
                 # TODO: refactor, put in common with MSBuildDeps. Beware this is != msbuild_arch
                 #  because of Win32
                 ("Platform", {'x86': 'Win32',
                               'x86_64': 'x64',
                               'armv7': 'ARM',
                               'armv8': 'ARM64'}.get(settings.get_safe("arch")))]

        name = "".join("_%s" % v for _, v in props if v is not None)
        condition = " And ".join("'$(%s)' == '%s'" % (k, v) for k, v in props if v is not None)
        return name.lower(), condition

It looks this might need some further parametrization. Can you please confirm that your Mixed Platforms is kind of "architecture" type selector? How it does connect to the underlying Conan settings.arch? Because that arch will have one of those values, isn't it? It could be a bit confusing to have a package with a package_id for arch=armv8, but the binaries that were built do not match that because they were "Mixed Platforms".
So the Platform seems limited to the architecture.

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

No branches or pull requests

2 participants