如何访问csproj文件中的宏变量? [英] How to access macro variables within csproj file?
问题描述
在我的csproj文件中,我具有不同的构建路径。
In my csproj file, I have a different build path.
<BaseIntermediateOutputPath>C:\Temp\Build\MyProject</BaseIntermediateOutputPath>
在构建前和构建后事件中,我可以访问某些宏变量。
When in the prebuild and post build events, I have access to certain macro variables.
$(OutDir)
$(ProjectName)
$(ProjectPath)
$(SolutionDir)
我可以在csproj中使用这些变量吗?
Can I use those variables within my csproj?
例如,我尝试以下操作未成功。
For example, I tried the following without success.
<BaseIntermediateOutputPath>C:\Temp\Build\$(ProjectName)</BaseIntermediateOutputPath>
推荐答案
我也有类似的要求,并使用$(MSBuildProjectName)
I had a similar requirement and using $(MSBuildProjectName) did the job for me.
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
<BaseIntermediateOutputPath>R:\$(MSBuildProjectName)\obj\</BaseIntermediateOutputPath>
</PropertyGroup>
这里R:是我的RAMDISK驱动器盘符。
Here R: is my RAMDISK drive letter.
对于其他可能也是面对正确设置RAMDISK驱动器号的问题,我使用了一个简单的VBS脚本
For others who may also face issues in setting up the RAMDISK drive letter correctly, I used a simple VBS script
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume") Where Label = 'RAMDISK'")
For Each objVolume in colVolumes
objVolume.DriveLetter = "R:"
objVolume.Put_
Next
这可确保将任何带有标签RAMDISK的驱动器设置为R:驱动器,而不是显示的默认驱动器。尽管这不属于您的问题,但我相信对于其他有类似要求(将objs文件用于RAMDISK并在vbproj / csproj文件中更改驱动器字母的情况)的人来说,这将很方便。
This ensures that any drive loaded with the label RAMDISK is set to R: drive instead of the default drive that appears. While this is not part of your Q, I am sure that this will be handy to others who have similar requirements of using the RAMDISK for their obj files and find the case of changing drive letters in vbproj/csproj files cumbersome.
- 保留的属性: http://msdn.microsoft.com/zh-cn/library/ms164309%28loband%29.aspx
- 更改驱动器号: http://www.activexperts.com/activmonitor / windowsmanagement / adminscripts / disk / drives /
- Reserved properties: http://msdn.microsoft.com/en-us/library/ms164309%28loband%29.aspx
- Changing drive letters: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/disk/drives/
这篇关于如何访问csproj文件中的宏变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!