How to access macro variables within csproj file?

半世苍凉 提交于 2019-12-12 08:49:17

问题


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)

Can I use those variables within my csproj?

For example, I tried the following without success.

<BaseIntermediateOutputPath>C:\Temp\Build\$(ProjectName)</BaseIntermediateOutputPath>

回答1:


I had a similar requirement and using $(MSBuildProjectName) did the job for me.

  <PropertyGroup>
    <ProjectView>ProjectFiles</ProjectView>
    <BaseIntermediateOutputPath>R:\$(MSBuildProjectName)\obj\</BaseIntermediateOutputPath>
  </PropertyGroup>

Here R: is my RAMDISK drive letter.

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

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.

References:

  1. Reserved properties: http://msdn.microsoft.com/en-us/library/ms164309%28loband%29.aspx
  2. Changing drive letters: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/disk/drives/


来源:https://stackoverflow.com/questions/8174614/how-to-access-macro-variables-within-csproj-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!