MsBuild: Get current directory of targets
Asked Answered
F

2

7

I have a msbuild target and it has a Import tag like this:

<Import Project="$(MSBuildExtensionsPath)\Company\Company.LifeCycle.targets" />

In contents of Company.LifeCycle.targets file, how can I get programatically the current directory (in this case is: C:\Program Files\MsBuild\Company) ??

I use VS 2008, .NET 3.5

Edit: I have seen the reference, How can I get current directory in msbuild script?, but not valid for me: $(MSBuildProjectDirectory give me this value, C:\Work\Company\Projects\Test001\ProyectSW3

Feltonfelts answered 5/10, 2010 at 10:1 Comment(1)
Does this answer your question? How can I get the current directory in an MSBuild script?Valerivaleria
W
11

With MSBuild 4 you can use the new property 'MSBuildThisFileDirectory' see my blog http://sedodream.com/2010/03/11/MSBuild40ReservedProperties.aspx. If you are not using MSBuild 4, you cannot do this easily.

Warfarin answered 5/10, 2010 at 14:31 Comment(4)
I use msbuild 3.5; source code not available for get new property 'MSBuildThisFileDirectory' like MsBuild Community Tasks or another extensions in codeplex ??Feltonfelts
No this is an update to MSBuild itself. Instead of getting the path it needs to be passed in via a property.Warfarin
@SayedIbrahimHashimi, your blog is not exactly clear on how to run the sample project there in order to see the reserved properties.Xylotomous
@TolaOdejayi the post has "msbuild ReservedProps02.proj /m /nologo" in the second code snippet.Warfarin
K
2

Your question has already been answered in another post here: MsBuild: Get current directory of targets. I hope the answers there satisfy you.

You can pretty much use MSBuildProjectDirectory which will give you the path to your current project file and you can build upon that.

Katlin answered 5/10, 2010 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.