简体   繁体   中英

Calling a target from csproj file

This question is related to a clickonce project that I am trying to publish.

Basically, I want to have a target run that does a publish for each testing environment so that I can set the publishurl and publishdir accordingly.

When building the project, I want to be able to call this new target without using the DefaultTargets or adding it in as a msbuild param. How can I call a certain target without these steps?

Ex: You can call a target from another target like:

<Target Name="ClientPublish">
    <CallTarget Targets="PublishForEachEnv" />
</Target>

But how would I call PublishForEachEnv target directly from the csproj?

Hope this makes sense

I'm not quite sure exactly what you mean, but I'll take a crack at it.

To edit your csproj, right click on it in the Solution Explorer, select Unload project . Then once it becomes greyed out and unavailable in the Solution Explorer, right click on it again and select Edit [your project name] .

The file is in XML, you can do all sort in there. If you look towards the bottom you'll see some target file imports, and you should also see an empty target each for BeforeBuild and AfterBuild. You can add the call to your custom target here, the AfterBuild is probably most appropriate for you. You could include your custom target inline in the csproj, or in an import file.

You'll have to go back to the Solution Explorer, right click on the project and select Reload Project for your changes to take effect.

Additionally there is another option: add a post build event which prints the value you are interested in to the build ouput window:

So, that means Solution Explorer, right click on the project, select Properties, the Build Events, then Edit Post-build.

You should be able to get what you want by entering the line

echo "My publish URL is: '$(PublishUrl)' "

Note that PublishUrl is not available to you in the macros list, but you can still use it by entering it manually - that list just contains common macros.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM