简体   繁体   English

从csproj文件中调用目标

[英]Calling a target from csproj file

This question is related to a clickonce project that I am trying to publish. 这个问题与我要发布的clickonce项目有关。

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. 基本上,我希望有一个针对每个测试环境进行发布的目标运行,以便可以相应地设置publishurl和publishdir。

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. 构建项目时,我希望能够调用此新目标,而无需使用DefaultTargets或将其添加为msbuild参数。 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? 但是我如何直接从csproj调用PublishForEachEnv目标?

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 . 要编辑csproj,请在“解决方案资源管理器”中右键单击它,然后选择“ 卸载项目” 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. 该文件为XML,您可以在其中进行所有排序。 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. 如果您看向底部,将会看到一些目标文件导入,并且还应该为BeforeBuild和AfterBuild分别看到一个空目标。 You can add the call to your custom target here, the AfterBuild is probably most appropriate for you. 您可以在此处将调用添加到自定义目标,AfterBuild可能最适合您。 You could include your custom target inline in the csproj, or in an import file. 您可以将自定义目标内联包含在csproj或导入文件中。

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)' " echo“我的发布URL为:'$(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. 请注意,在宏列表中您无法使用PublishUrl ,但是您仍然可以通过手动输入它来使用它-该列表仅包含公共宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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