I have a .NET Core 8.0 desktop app that I can publish either via folder or via ClickOnce.
For the folder solution I got something like:
<Target Name="ExecuteSomething" AfterTargets="Publish" Condition="'$(Configuration)' == 'Release'">
<Exec Command='"Path\To\Something.exe"; "$(PublishDir)MyApp.dll.config"'/>
</Target>
Which runs an script that alters the dll.config
file (something required to be done for every publish). Now I need to do the same for the ClickOnce so the MyApp.dll.config.deploy
file is modified.
I tried acting on the PublishUrl
folder, but the sub-folder Application Files\MyApp_VersionNumber_Revision
doesn't exist yet when the "ExecuteSomething" target takes place after the target "Publish". Also, acting on the PublishDir
doesn't work either as while I may get the change to take effect there, it doesn't propagate to the ".deploy" file on the PublishUrl
later.
What are my options then?
Is there any way I can act on the MyApp.dll.config
before it gets copied to the PublishUrl
as a MyApp.dll.config.deploy
so that the changes to it persist?
I have tried acting on the PublishDir
, acting on the PublishUrl
and on the "Build"
folders, without success. Both before and after publish when possible.
I have a .NET Core 8.0 desktop app that I can publish either via folder or via ClickOnce.
For the folder solution I got something like:
<Target Name="ExecuteSomething" AfterTargets="Publish" Condition="'$(Configuration)' == 'Release'">
<Exec Command='"Path\To\Something.exe"; "$(PublishDir)MyApp.dll.config"'/>
</Target>
Which runs an script that alters the dll.config
file (something required to be done for every publish). Now I need to do the same for the ClickOnce so the MyApp.dll.config.deploy
file is modified.
I tried acting on the PublishUrl
folder, but the sub-folder Application Files\MyApp_VersionNumber_Revision
doesn't exist yet when the "ExecuteSomething" target takes place after the target "Publish". Also, acting on the PublishDir
doesn't work either as while I may get the change to take effect there, it doesn't propagate to the ".deploy" file on the PublishUrl
later.
What are my options then?
Is there any way I can act on the MyApp.dll.config
before it gets copied to the PublishUrl
as a MyApp.dll.config.deploy
so that the changes to it persist?
I have tried acting on the PublishDir
, acting on the PublishUrl
and on the "Build"
folders, without success. Both before and after publish when possible.
- what kind of changes are you making in the config file? you are making dynamic changes? – Jalpa Panchal Commented Mar 20 at 10:23
- @jalpa-panchal it was a dynamic change as the result of the execution would be dependent on some publish parameters (including but not limited to: version/revision, execution timestamp, etc.). I had to settle for having it execute before the Restore phase so changes would carry over without affecting the hashes. However, I wrote one option to execute it on the published file for future reference as for cases where it doesn't introduce changes to the file (imagine the .exe does some verification and returns a result/error code but keeps the file as is), it might be a valid approach. Thanks! – acd_ Commented Mar 20 at 11:51
1 Answer
Reset to default 1So, after looking for alternatives for a while and checking the log for the publishing I found that before the final published files are moved to the Applications Files
folder in the PublishUrl
, the structure is replicated inside the PublishDir
and deleted once moved to the final destination. Therefore, when doing any action during an "AfterTargets="Publish"
target, if trying to act upon the .deploy
files any command must point to the $(PublishDir)Application Files\...
contents.
My final solution was something like the code shown bellow. The "replaces" are in place so that one can get the version-revision string in a "MyApp_X_X_X_X"
format.
<Target Name="ExecuteSomething" AfterTargets="Publish" Condition="'$(Configuration)' == 'Release'">
<Exec Command='"Path\To\Something.exe"; "$(ProjectDir)$(PublishDir)Application Files\$(AssemblyName)_$(ApplicationVersion.Replace(.,_).Replace(*,$(ApplicationRevision)))\MyApp.dll.config.deploy"'/>
</Target>
This does work for using the file as an input for the executable, however, if there are changes in the file after the execution, the later installation will fail as the hashing won't match. For that case, better act before the Build
or Restore
phases take place.