Quantcast
Channel: MSBuild forum
Viewing all articles
Browse latest Browse all 2763

Insert Import into project file at position 0 and save without prompt

$
0
0

I am building a Nuget package which has a tools folder with install.ps1. This Nuget package is dependent on NugetPowerTools package which provides some APIs to work with the project and its properties. I have pasted the code used in my install.ps1 below.

param($installPath, $toolsPath, $package, $project)
$buildProject = Get-MSBuildProject
$import = $buildProject.Xml.AddImport("Custom.Targets")
$buildProject.Save()

I have 2 questions.

1. The AddImport appends the target at the end (i.e., after other Import lines). I need to have my Import as the first line (since I have some functionality in this targets file which needs to be executed before others). Is it possible to insert the Import at first (i.e., my import with Custom.Targets should be the first item of Import in the project file)? I can't find an Insert method.

2. Once the project file is modified by this install.ps1, there is a pop up /prompt in Visual Studio with 4 options namely, SaveAs, Discard, Overwrite and Ignore. I want to save & overwrite the project file without this prompt / pop up from my install.ps1. This is to avoid any accidental mistake by the user. To overcome, I found a link below, which has the following line of code, which helps me overcome this issue.

https://stackoverflow.com/questions/12292577/how-can-i-reload-a-visual-studio-project-thru-a-nuget-powershell-script

$(get-item $project.FullName).lastwritetime=get-date

But now, I get another pop up / prompt with options to Reload, Reload All, Ignore, Ignore All. Is there a way to Reload this project without this prompt?

Please help.


Ven




Viewing all articles
Browse latest Browse all 2763

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>