-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
PublishSelfContained should work with /t:Publish #32272
Comments
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsDescriptionWhen publishing a trimmed app, I am currently getting an error:
Even though I'm setting Reproduction Steps<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<PublishSelfContained>true</PublishSelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<!-- Set SelfContained=false to prevent the whole runtime from being copied into the build output directory -->
<SelfContained>false</SelfContained>
</PropertyGroup>
</Project> Running <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<PublishSelfContained>true</PublishSelfContained>
</PropertyGroup>
</Project> Expected behaviorI expect both apps above to publish successfully. Actual behaviorBoth of them produce the above error. Regression?No response Known WorkaroundsExplicitly specify ConfigurationNo response Other informationNo response
|
Looking at the way sdk/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets Lines 66 to 68 in 4263fdd
It looks like it just sets I think that the intention is for this to be resolved via #30038 (so you won't have to explicitly set SelfContained=false to get the desired behavior). There might be a way to work around this by setting But I think this is currently by design. cc @nagilson |
Seems like there's an open question here: is |
|
It looks like there are larger issues here even if you take the "recommended" path and set |
That seems like a mistake.
When automating the build of a large repo, it doesn't make sense to jump in and out of MSBuild to
If we want users to forward/check/set that property, we should give it an official name without an |
Just an example of this in dotnet/runtime: This one folder has 20 trimming tests. When I run them (from the root of dotnet/rutnime):
and inspect the folder that contains these test projects: |
@eerhardt I hear you. We tried very hard to get it to work for MSBuild publish. It also doesn't work inside of VS outside of the context of running a There are several reasons we landed here. We could technically create some logic in MSBuild to make it work, but it wouldn't work very well. Adding this to MSBuild would break several key philosophies of MSBuild. One of the problems is that people need to be able to write their own custom publish targets or call the Publish target in their build whenever. We don't know at the very beginning of the build if someone is going to inject a publish target. But we need the One of the only ways (if the only) to get around that is to run the build/publish twice, so you can see in the 1st time if publish is ever invoked and commmunicate that to the 2nd run. But that's pretty bad.
This is a good suggestion and we could do that. But it sounds like there are problems even if that's used, which is unfortunate. I am trying to think if there is any other solution for this scenario. |
dotnet/runtime#95496 is another example where |
@marcpopMSFT @dsplaisted @baronfel - is there any chance this can be fixed in the near future? I think this behavior is causing a lot of confusion - and extra work debugging failures because of this. |
See Noah's comment above. It's particularly challenging to make specific SDK properties work when targets are executed directly through msbuild target invocation. We can have another discussion to see if there are better options but we don't want to maintain that separation between MSBuild and SDK. |
I think the minimum we could do is what I suggested in dotnet/runtime#95496 (comment)
This seems like it would fix most (if not all?) of the issue here. |
It seems like the core challenge is that Doing this via Would it solve some of these issues if the Publish target instead invoked |
This is also affecting WinAppSDK, specifically this broke with the .NET 9 SDK. In order to publish something using WinAppSDK (eg. a WinRT component, or a WinUI 3 app) you need
On .NET 9 fails to build with that same error mentioned here (can't optimize for size). Adding |
Description
When publishing a trimmed app, I am currently getting an error:
Even though I'm setting
PublishSelfContained=true
in my .csproj. I am also settingSelfContained=false
because I don't want all of the runtime copied into my build output directory. I have many applications that I'm publishing (test apps in dotnet/aspnetcore) and each application is taking up ~100 MB in thebin
directory. This is unnecessary bloat.Reproduction Steps
Running
dotnet msbuild /t:Publish
on that project will fail. It will also fail just for:Expected behavior
I expect both apps above to publish successfully.
Actual behavior
Both of them produce the above error.
Regression?
No response
Known Workarounds
Explicitly specify
SelfContained=true
, but that causes bloat (will eventually be GBs) in my bin directory.Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: