Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
904 views
in Technique[技术] by (71.8m points)

visual studio - How to set a VSPROPS variable only if it does not already exist?

Say I've got a .vsprops file that is used in a solution. In that file, various variables are defined such as int_dir for intermediate build results and log_dir for the log results.

Usually, these variables get set to default values (relative to the solution).

For me, I'd like to set these two variables to my ramdisk (R:), i.e. no longer

$(SolutionDir)intermediate

but

R:myprojectintermediate

If I change the .vsprops file directly, the source control (Git) will mark it as modified.

Is there a way in VSPROPS so that I could check maybe an environment variable and if this variable is not set, the default is used?

If this is not possible, I'd also be interested in a solution for Git to overcome this (but not --assume-unchanged and not .gitignore because maybe other changes in that file could be relevant).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A pure Git solution could use a gitattribute filter driver:

content filter

It would involve a smudge script, executed on git checkout, which would:

  • detect if you want to change $(SolutionDir) (for instance, test for an environment variable with the updated path in it)
  • detect the right file (xxx.vsprops.tpl) content (the script doesn't know the file names or path it operates on)
  • generate the actual .vsprops from a .vsprops.tpl (template file) which is the one being versioned (the .vsprops is no longer versioned)

You can add a clean script which would preserve (on git commit) all the modification done in the .vsprops file back to the .vsprops.tpl, except for the $(SolutionDir) line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...