pubxml web publish tool Event Lifecycle - asp.net

I am using the Web publishing tool from Visual Studio 2012 to publish to File System. I learned that I can open my *.pubxml in the Properties folder to do more advanced things.
What I want to do is run a command line application at the end of the publishing task.
I would usually do it in a Custom Target and execute it after one of the build in Events like this.
<Target Name="CustomAfterPublish" AfterTargets="GatherAllFilesToPublish">
</Target>
The problem is that GatherAllFilesToPublish is way to early because I want to execute it at the very last, after publishing was done.
Is there a list or does someone know the build in events and there order in which they are fired? Basically the Event Lifecycle of a FileSystem web publish.
Or how can I fire a Target manually at the very end?
I tried following without success:
<Target Name="Msg" AfterTargets="PipelineDeployPhase;MSDeployPublish;Package">
And also every each of them individually.
So what's the very last hook of the publishing lifecycle?
---> Edited
I added already tracing. The problem is that the files were copied to a temp path and after that all files are deleted. So copying to the destination will not work after "GatherAllFilesToPublish"See my trace from the command line window here...
1>------ Build started: Project: Dependency of a project: Release Any CPU ------
2>------ Build started: Project: Dependency of another project, Configuration: Release Any CPU ------
3>------ Build started: Project: Web, Configuration: Release Any CPU ------
4>------ Publish started: Project: Web, Configuration: Release Any CPU ------
4>Transformed Web.config using C:\...\Web.Release.config into obj\Release\TransformWebConfig\transformed\Web.config.
4>Copying all files to temporary location below for package/publish:
4>obj\Release\Package\PackageTmp.
**<------------- Here is the place where my excutable is called ---------------------------------**
4>Deleting existing files...
4>Publishing folder /...
4>Publishing folder App_Browsers...
4>Publishing folder App_Themes...
4>Publishing folder bin...
4>Site was published successfully file:///C:/Test
4>
========== Build: 3 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
Thanks for any help.

As far as I can tell GatherAllFilesToPublish is the last event available. However, depending on your requirements you may still be able to use this event.
Instead of performing operations on files in the final publish location, you can target the intermediate files written to the location below (where ProjectDir is the folder of your project obviously)
/ProjectDir/obj/Release/Package/PackageTmp/
It seems that Visual Studio does a straight copy of all files in this directory. So, when hooking into GatherAllFilesToPublish you should be able to make any changes to the files in this directory and they will be reflected in the final publish location.
Related Information
If you'd like to verify that GatherAllFilesToPublish is truly the last event you can do this yourself by enabling Diagnostic build output.
Tools -> Options -> Projects and Solutions -> Build and Run -> MSBuild
project build output verbosity -> Diagnostic
Build the project and search for Done building target "GatherAllFilesToPublish", for me this was the last trigger before it started copying the files to the publish location.

I had the same problem. Your solution
Coping first to the temp directory and let web publish picking up the
coping for publishing
was helpful.
I just want to share for other people how it can be done:
<Target Name="CopyConfigForPublish" AfterTargets="CopyAllFilesToSingleFolderForPackage" Condition="exists('$(SolutionDir)Web.Common\bin\$(Configuration)\Log.config')">
<Copy SourceFiles="$(SolutionDir)Web.Common\bin\$(Configuration)\Log.config" DestinationFolder="$(WPPAllFilesInSingleFolder)" />
</Target>

I had a similar issue.
As far as i could check, "GatherAllFilesToPublish" is the last target you can deal with. You can use it doing an AfterTargets.
And use this >
$(MSBuildProjectDirectory)\obj\Release\Package\PackageTmp
To manipulate anything there.
What I did was creating an .bat file to do the dirty work.
You can find out which one is the variable that stores the relative part of the path (\obj\Release\Package\PackageTmp) and use it on more refined way.

Related

Can .Net Core 3 self-contained single executable be decompiled?

I tried using Dotpeek and ILSpy.Net to decompile (my own code), they failed.
Do I need special obfuscation on distributed binaries of .Net Core 3 self-contained single executable ?
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
</Project>
The single-file exe is really an unmanaged wrapper and ILSpy doesn't support decompiling this. But when you run the exe, it unwraps its contents to a temp folder. So you can find the managed dll there and decompile it using ILSpy.
To find the temp folder, you can use any tool that shows locations of assemblies loaded by a process. SysInternals Process Monitor (procmon) is a good one.
You can setup procmon to filter by your exe name, and when you launch your exe, procmon should show some events for assemblies being loaded from a temp folder:
You can browse to that folder and find your managed dll there. And you can decompile using ILSpy from that location.
I wrote a blog entry: https://eersonmez.blogspot.com/2020/02/ilspy-decompiling-net-core-self.html
I wrote a small dotnet tool after I stumbled upon this question and couldn't find a lightweight tool myself other than ILSpy.
You can install it using the following dotnet command: dotnet tool install -g sfextract.
After installing it, run it using the following command: sfextract application.exe -o output-dir
The bundle format for .NET 5.0 (bundle version 2) is identical to previous versions. .NET 6.0 (bundle version 6) has an additional field for each file entry containing the compressed size, since single-file applications can now be compressed using gzip by setting EnableCompressionInSingleFile to true.
https://www.nuget.org/packages/sfextract/
https://github.com/Droppers/SingleFileExtractor
Update 07/2022: .Net 5 single-file does not automatically unpack to the same temporary location as before. to force it to be unpacked you would need to add the following:
in the project file add these properties (according to theseMicrosoft docs):
<PublishSingleFile>true</PublishSingleFile>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
Add an environment variable DOTNET_BUNDLE_EXTRACT_BASE_DIR with the location you want the files extracted to.
Update: One of the announcements made regarding .Net 5 states that the way single-file executables will be made would change, so this method will not work for them.
I wanted to add on #Eren Ersönmez's answer, that while ILSpy DotPeek don't support this at the time, since the self-contained single file is just a wrapper that contains all your DLLs and gets extracted on runtime, simply knowing where it is extracted to can save you using ProcMon or ProExp or windbg.
If you use windows you can go to c:\Users\{Local Username}\AppData\local\temp\.net\{Name of executable}
which should lead to somewhere similar to
c:\Users\alenros\AppData\Local\Temp.net\MyTestApplication
Launch your exe, and a folder with the same name will be created in that location.
The folder will contain randomly named folders. open the latest one and there you will find all your extracted DLLs, which can then be decompiled.

Visual Studio Team Services dotnet publish

My build completes with no errors, but it creates a randomly named zip file (s.zip) for the release step.
After the release step, I end up with that s.zip in inetpub/wwwroot/admin-tool/ folder. I'm almost there, but I want it to unzip and dump all the contents in here. This should be automatic, shouldn't it?
My dotnet publish looks like this:
and cause this to run, which is how I get the s.zip:
C:\Program Files\dotnet\dotnet.exe publish C:\agent\_work\3\s\Angular.AdminTool.csproj -c release --output C:\agent\_work\3\a\s
If I try to edit the -o argument and make it -o $(Build.ArtifactStagingDirectory)/admin-tool I will just end up with C:\agent\_work\3\a\admin-tool\s.zip
Is getting the name of my zip to be the same as the name of my web-site (admin-tool) the key to getting the zip to automatically extract in the release step?
In case it help others, I used the simple command line tools rather than the pre-canned "dotnet core" ones:
and for the Archive files task, be sure to include a hard-coded name for the zip to be used in the build process:
And for the release, in the "Deploy IIS App" task, be sure to include the full path for the zip file:
I also ran into this issue but solved it another way.
In my case I have a single project to build and deploy.
The $(Parameters.RestoreBuildProjects) value is set to a single project
MyProjectFolder/MyProject.csproj.
In the .Net Core Publish task, this value is used in the Path to Project(s) field.
Then I tick both the boxes for
I saved and queued this pipeline.
The zip file created seems to be derived from the name of the folder
so I ended up with a zip file in the artifact staging directory with the name of the project. Then the Publish Artifact task placed this zip file into the Artifact that is named in that task.

TeamCity MSbuild Deploy procedure

I'm using TeamCity for deployment process. For deploy i'm running MSbuild with this command line parameters:
/P:Configuration=Release
/P:DeployOnBuild=True
/P:DeployTarget=MSDeployPublish
/P:MsDeployServiceUrl=serviceUrl
/P:DeployIisAppPath=website
/P:AllowUntrustedCertificate=True
/P:MSDeployPublishMethod=WMSvc
/P:username=username
/P:Password=password
/P:SkipExtraFilesOnServer=True
/P:VisualStudioVersion=10.0
I have this parameter P:SkipExtraFilesOnServer set to true beacause i don't want MSbuild to delete some files which i have only on service enviroment, but don't have on my local project. But the problem is when i actually want to remove something from project (i have web application), i usually delete file from project, then i rebuild my app, and commit the changes in project file to source control, MSbuild leave this file on service because of this parameter.
MSbuild is using Release configuration, which i specified to use "all files in this project" to deploy. So the behaviour i want to implement:
TeamCity will leave all files which are not in my project reference list. (.csproj file).
TeamCity will delete files which were in .csproj but was deleted from it.
Please help me with that task.

How To Run MSBuild scripts in .wixproj?

Im trying to learn to make a web installer using Windows Installer XML (WIX 3.5). I found this blog about using msbuild in .wixproj files to avoid the scenario where the installer ends up dropping the web project assemblies right in the root of the app instead of keeping them in the bin folder like they're supposed to be.
Here is the link to that:
<http://www.paraesthesia.com/archive/2010/07/30/how-to-consume-msdeploy-staged-web-site-output-in-a.aspx>
But after adding the MSBuild scripts in the .wixproj file, I don't know what to do anymore. According to the instruction after adding the MSBuild script:
"When that target runs, you'll see a .wxs file pop out in the .wixproj project folder. Add the generated .wxs to your .wixproj project so it knows to include it in the build."
I really don7t know what this means. How can I run the target? I tried to build it but there was no .wxs file generated in the .wixproj folder.
Am I missing something? Please help...
Assuming you have added the section from the tutorial:
<Target Name="BeforeBuild">
...
</Target>
The target will be run automatically when you build the project. The "BeforeBuild" target is one of the standard entry-points to add your own modifications to the build. The target will then generate a file (named [WebProjectName].wxs that is placed in the same directory as your wixproj file. Click on the show all files button in visual studio and right-click on the file and "Include in project" That will then include the wxs is your installer and when you next build it will have the correct folder/file structure.

Web Setup project not generating .msi file

I have a solution with a web setup project and a large website project in visual studio 2008.
When building the setup project it removes the setup.exe and the .msi file (which it is supposed to), the error occurs when it creates these files.
It creates the setup.exe file but not the .msi file, in its place is a .tmp
Let me know if more information is needed. I am thankful for the help.
Below is the output window and error.
------ Build started: Project: C:\...\GrandUnifiedWebSliceTheory\, Configuration: Debug Any CPU ------
Validating Web Site
Building directory '/GrandUnifiedWebSliceTheory/19002_DistrictManagement/'.
Building directory '/GrandUnifiedWebSliceTheory/19005_ManualAdjustment/'.
Building directory '/GrandUnifiedWebSliceTheory/19010_AllStatementListing/'.
Building directory '/GrandUnifiedWebSliceTheory/19050_MortgageExport/'.
Building directory '/GrandUnifiedWebSliceTheory/19060_StatementDataExport/'.
Building directory '/GrandUnifiedWebSliceTheory/24570_ParcelPermit/'.
Building directory '/GrandUnifiedWebSliceTheory/29571_OpenSpaceTimberRemoval/'.
Building directory '/GrandUnifiedWebSliceTheory/29572_DFLRemoval/'.
Building directory '/GrandUnifiedWebSliceTheory/29605_ExemptStatusChange/'.
Building directory '/GrandUnifiedWebSliceTheory/29606_DestroyedProperty/'.
Building directory '/GrandUnifiedWebSliceTheory/82005_GDoc_BuildingPermit/'.
Building directory '/GrandUnifiedWebSliceTheory/9520_QuickViewAA/19097_RelatedSta/'.
Building directory '/GrandUnifiedWebSliceTheory/9520_QuickViewAA/19098_TxRollCorrect/'.
Building directory '/GrandUnifiedWebSliceTheory/9520_QuickViewAA/24555_BuildingPermit/'.
Building directory '/GrandUnifiedWebSliceTheory/9520_QuickViewAA/25030_ParcelSaleHistory/'.
Building directory '/GrandUnifiedWebSliceTheory/9520_QuickViewAA/25099_QuickValueSummary/'.
Building directory '/GrandUnifiedWebSliceTheory/9520_QuickViewAA/9702_GISImaging/'.
Building directory '/GrandUnifiedWebSliceTheory/9521_QuickViewTR/19097_RelatedSta/'.
Building directory '/GrandUnifiedWebSliceTheory/9521_QuickViewTR/19098_TxRollCorrect/'.
Building directory '/GrandUnifiedWebSliceTheory/9521_QuickViewTR/19099_Ownership/'.
Building directory '/GrandUnifiedWebSliceTheory/9521_QuickViewTR/25030_ParcelSaleHistory/'.
Building directory '/GrandUnifiedWebSliceTheory/9521_QuickViewTR/25099_QuickValueSummary/'.
Building directory '/GrandUnifiedWebSliceTheory/9521_QuickViewTR/95020_StatementHeaders/'.
Building directory '/GrandUnifiedWebSliceTheory/9521_QuickViewTR/JS/'.
Building directory '/GrandUnifiedWebSliceTheory/96010_OwnerSummary/'.
Building directory '/GrandUnifiedWebSliceTheory/JS/'.
Building directory '/GrandUnifiedWebSliceTheory/'.
Validation Complete
------ Starting pre-build validation for project 'GuwtSetup' ------
------ Pre-build validation for project 'GuwtSetup' completed ------
------ Build started: Project: GuwtSetup, Configuration: Release ------
Building file 'C:\Documents and Settings\Desktop\svn\GrandUnifiedWebSliceTheory\GuwtSetup\Release\GuwtSetup.msi'...
**ERROR: Could not find file 'C:\Documents and Settings\Desktop\svn\GrandUnifiedWebSliceTheory\GuwtSetup\Release\GuwtSetup.msi' 'The system cannot find the file specified.'**
========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========
Figured it out thank you for all the views. The answer was, somehow in the project properties the web setup project release checkbox was marked. Unchecking this box allowed somehow fixed the problem
Watch the output panel, it will probably indicate what the error is.
Figured it out thank you for all the views. The answer was, somehow in the project properties the web setup project release checkbox was marked. Unchecking this box allowed somehow fixed the problem

Resources