小编Don*_*ing的帖子

如何从Visual Studio 2010运行PowerShell脚本

如果我在Visual Studio中有.ps文件,我该如何在项目的上下文中运行它?

powershell visual-studio-2010 visual-studio

16
推荐指数
2
解决办法
1万
查看次数

如何使用Powershell编辑XML?

我正在尝试在Powershell中编辑一些xml.这是我正在做的事情:

$path = 'C:\Projects\NuGetTestPackage\NuGetTestPackage'
$projName = 'NuGetTestPackage1.csproj'
cd $path
$file = gi $projName
$pattern = 'TextTemplatingFileGenerator'
$xml = [xml](gc $file)
$node = [xml] $xml.Project.ItemGroup.None.Generator | 
    Where { $_.Project.ItemGroup.None.Generator -eq $pattern } |
    Foreach {$_.Project.ItemGroup.None.Generator = ''}
$xml.Save($file.Fullname)
Run Code Online (Sandbox Code Playgroud)

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{E750ACF1-17B5-4D83-8FC8-5A4488193099}</ProjectGuid>
    <ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>NuGetTestPackage</RootNamespace>
    <AssemblyName>NuGetTestPackage</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <MvcBuildViews>false</MvcBuildViews>
    <UseIISExpress>false</UseIISExpress>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize> …
Run Code Online (Sandbox Code Playgroud)

xml powershell

11
推荐指数
1
解决办法
1万
查看次数

PowerShell解析xml并保存更改

我正在解析一个用于nuget安装的csproj文件,并且我有一个需要更改的节点.有问题的节点是名为"Generator"的节点,其值等于"TextTemplatingFileGenerator",其父节点的属性为"WebConfigSettingsGeneratorScript.tt"(第二部分尚未在此处).

这是我已经获得的脚本,但它还没有完成.它正在工作,但它保存了一个空文件.此外,它没有我的where子句的第二部分,也就是说

$path = 'C:\Projects\Intouch\NuGetTestPackage\NuGetTestPackage'
cd $path
$files = get-childitem -recurse -filter *.csproj
foreach ($file in $files){
    ""
    "Filename: {0}" -f $($file.Name)
    "=" * ($($file.FullName.Length) + 10)   

    if($file.Name -eq 'NuGetTestPackage1.csproj'){
        $xml = gc $file.FullName | 
        Where-Object { $_.Project.ItemGroup.None.Generator -eq 'TextTemplatingFileGenerator' } | 
        ForEach-Object { $_.Project.ItemGroup.None.Generator = '' }
        Set-Content $file.FullName $xml
    }   
}
Run Code Online (Sandbox Code Playgroud)

这是XML的基本版本:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <None Include="T4\WebConfigSettingGeneratorScript.tt">
      <Generator>TextTemplatingFileGenerator</Generator>
      <LastGenOutput>WebConfigSettingGeneratorScript.txt</LastGenOutput>
    </None>
Run Code Online (Sandbox Code Playgroud)

非常感谢.我是一个完整的PowerShell n00b!

xml powershell

10
推荐指数
2
解决办法
3万
查看次数

如何使用PowerShell编辑.csproj文件 - Visual Studio 2010

我需要一些使用PowerShell编辑csproj文件的帮助.我基本上需要选择一个节点并改变它.

例:

<None Include="T4\WebConfigSettingGeneratorScript.tt">
  <Generator>TextTemplatingFileGenerator</Generator>
  <LastGenOutput>WebConfigSettingGeneratorScript1.txt</LastGenOutput>
</None>
Run Code Online (Sandbox Code Playgroud)

我需要从此标记中删除TextTemplatingFileGenerator属性.

powershell visual-studio-2010

7
推荐指数
1
解决办法
4520
查看次数

Visual Studio 2015 minify“访问路径bundleconfig.json被拒绝”

问题是,当我右键单击“缩小文件”时,Visual Studio 没有缩小,而是给出了此错误:“访问路径 bundleconfig.json 被拒绝”。

我确信我错过了一些简单的事情。

minify visual-studio bundling-and-minification asp.net-bundling

5
推荐指数
1
解决办法
959
查看次数