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

Error "Unable to activate Windows Store app" when Directory.Build.targets changes assembly name.Bug title #4606

Closed
voroninp opened this issue Jul 30, 2024 · 3 comments

Comments

@voroninp
Copy link

Describe the bug

I define a prefix for assemblies in Directory.Build.props:

<AssemblyPrefix Condition="$(AssemblyPrefix) == ''">MorozCo</AssemblyPrefix>
<AddPrefixToAssembly Condition="$(AddPrefixToAssembly) == ''">true</AddPrefixToAssembly>
<AddPrefixToNamespace Condition="$(AddPrefixToNamespace) == ''">true</AddPrefixToNamespace>

And set names in Directory.Build.targets:

<PropertyGroup>
  <AssemblyName Condition="$(AssemblyName) == ''">$(MSBuildProjectName)</AssemblyName>
  <AssemblyName Condition="$(AddPrefixToAssembly) == 'true' and $(AssemblyPrefix) != '' and !$(AssemblyName.StartsWith(AssemblyPrefix))">$(AssemblyPrefix).$(AssemblyName)</AssemblyName>
</PropertyGroup>

<PropertyGroup>
  <RootNamespace Condition="$(RootNamespace) == ''">$(AssemblyName.Replace(' ', '_'))</RootNamespace>
  <_RootNamespacePrefix>$(AssemblyPrefix.Replace(' ', '_'))</_RootNamespacePrefix>
  <RootNamespace Condition="$(AddPrefixToNamespace) == 'true' and $(_RootNamespacePrefix) != '' and !$(RootNamespace.StartsWith(_RootNamespacePrefix))">$(_RootNamespacePrefix).$(RootNamespace)</RootNamespace>
</PropertyGroup>

If I do not set <AddPrefixToAssembly>false</AddPrefixToAssembly> in my MAUI project, I get this error:

Unable to activate Windows Store app 'com.companyname.myapp_9zz4h110yvjzm!App'. The activation request failed with error 'The system cannot find the file specified'.

Steps to reproduce the bug

See this repo
https://github.com/voroninp/BadWindows

Expected behavior

No response

Screenshots

No response

NuGet package version

None

Packaging type

Unpackaged

Windows version

No response

IDE

Visual Studio 2022-preview

Additional context

Advised here to create issue.

@evelynwu-msft
Copy link
Contributor

evelynwu-msft commented Jul 30, 2024

@voroninp We derive a number of properties from the value of AssemblyName. Because stuff in Directory.Build.targets runs after basically everything else this simply isn't a scenario that can be reasonably supported. My recommendation would be that you take the logic you currently have in Directory.Build.targets and place it into some common .targets file that each .csproj manually imports at the bottom. I know this isn't as elegant as you would like but it's just how MSBuild works.

@evelynwu-msft evelynwu-msft closed this as not planned Won't fix, can't repro, duplicate, stale Jul 30, 2024
@voroninp
Copy link
Author

Are not SDK targets run the last?

@evelynwu-msft
Copy link
Contributor

Windows App SDK is a Nuget package, not a .NET SDK, so its .targets runs before Directory.Build.targets.

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