Reputation: 144
I have an asp.net project and need to run some code after each publish.
I tried to acomplish this using to ways:
Useing external build tool Cake (c# make)
1.) So found some topics related to this issue:
So like suggested i added following code to my project file:
<Target Name="BeforePublish">
<Message Text="BeforePublish"></Message>
<Warning Text="BeforePublish"></Warning>
</Target>
<Target Name="AfterPublish">
<Message Text="AfterPublish"></Message>
<Warning Text="AfterPublish"></Warning>
</Target>
<Target Name="MSDeployPublish" >
<Message Text="MSDeployPublish"/>
<Warning Text="MSDeployPublish"/>
</Target>
<Target Name="PipelinePreDeployCopyAllFilesToOneFolder" >
<Message Text="PipelinePreDeployCopyAllFilesToOneFolder" />
<Warning Text="PipelinePreDeployCopyAllFilesToOneFolder" />
</Target>
<Target Name="BeforeBuild">
<Message Text="BeforeBuild"></Message>
<Warning Text="BeforeBuild"></Warning>
</Target>
<Target Name="AfterBuild">
<Message Text="AfterBuild"></Message>
<Warning Text="AfterBuild"></Warning>
</Target>
But only the Before- & AfterBuild get executed. All the other targets just get ignored completly. Maybe it's because these other topics use VS 2010 and 2012. Is there a working way to do this in VS 2017?
2.) When i use following code in a task I don't get same output as when i would have compiled it with VS.
MSBuild(projectFile, new MSBuildSettings()
.WithProperty("OutDir", publishDir)
.WithProperty("DeployTarget", "WebPublish")
.WithProperty("DeployOnBuild", "true")
.WithProperty("WebPublishMethod", "FileSystem")
.WithProperty("Configuration", "Release")
);
Therefore this isn't a viable solution atm as well.
I am thankful for any help getting this to work one way or another.
Upvotes: 4
Views: 1700
Reputation: 28196
1.) So found some topics related to this issue. So like suggested i added following code to my project file. Actually,after my test in vs2017, from the output log with detailed, what I can find when publishing is like pics below:
1.It seems in VS2017, when publishing the project in IDE, there has no valid publish target to redefine or AfterTargets. So I'm afraid you can't achieve this goal by publishing in VS.
2.Instead, I think you can consider using msbuild tool. Add test target script below into your Publish profile (For me:FolderProfile.pubxml):
<Project...>
...
<Target Name="Test" AfterTargets="WebFileSystemPublish">
<Message Text="I'm a test target after webpublish"/>
<Move SourceFiles="C:\Ase\favicon.ico" DestinationFolder="C:\tomorrow"/>
</Target>
</Project>
Open your developer command prompt for vs2017, and type command like:
msbuild C:\xxx\WebApplication55\WebApplication55.sln /p:DeployOnBuild=true /p:PublishProfile=C:\xxx\repos\WebApplication55\WebApplication55\Properties\PublishProfiles\FolderProfile.pubxml
It will run the test target after webpublish process.
2.) When i use following code in a task I don't get same output as when i would have compiled it with VS. Not sure you use this code for what. But you can use test target to do what you want.Add a MSBuild Task into test target can achieve this goal for your #2.
And as you mentioned you have some code, compile those code to a .exe first, and add a Command Task into test target could help. In addition: According to your info above, it seems you use file system and asp.net, so I use asp.net web app to test(not .net core). A feedback would be expected.
Upvotes: 0
Reputation: 164
It depends on what you want to do after but if you want your code to run after publish you need to put your task after one of the targets from Microsoft.Web.Publishing.targets (search for the file to see full list of targets). Usually you need AfterTargets="MSDeployPublish"
Upvotes: 1