Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 有“a”这样的东西吗;“仅内容/数据项目”;在VisualStudio中_Visual Studio_Visual Studio 2008 - Fatal编程技术网

Visual studio 有“a”这样的东西吗;“仅内容/数据项目”;在VisualStudio中

Visual studio 有“a”这样的东西吗;“仅内容/数据项目”;在VisualStudio中,visual-studio,visual-studio-2008,Visual Studio,Visual Studio 2008,我有一大堆辅助XML和XSLT文件,我想在VisualStudio中编辑和管理它们 这些文件在逻辑上不属于我的解决方案中的任何代码项目,因此为了将它们整齐地分组,我在VisualStudio中创建了一个“虚拟”C#dll项目,并在调试/发布版本中禁用了它 我想知道是否有更好的方法来实现相同的结果(即在解决方案资源管理器中显示所有文件)。我认为我真正想要的是一个VisualStudio项目类型的“仅内容”,但这样的东西并不存在(或者我没有足够努力地去寻找?) 我曾经尝试过将文件添加为解决方案项,但

我有一大堆辅助XML和XSLT文件,我想在VisualStudio中编辑和管理它们

这些文件在逻辑上不属于我的解决方案中的任何代码项目,因此为了将它们整齐地分组,我在VisualStudio中创建了一个“虚拟”C#dll项目,并在调试/发布版本中禁用了它

我想知道是否有更好的方法来实现相同的结果(即在解决方案资源管理器中显示所有文件)。我认为我真正想要的是一个VisualStudio项目类型的“仅内容”,但这样的东西并不存在(或者我没有足够努力地去寻找?)

我曾经尝试过将文件添加为解决方案项,但它们似乎更难管理,因为创建新的“解决方案项文件夹”实际上并不会在磁盘上创建文件夹


有人有什么想法吗?

然后,尝试创建一个
空白解决方案。创建
空项目
。将文件放在解决方案文件夹中的相应文件夹中。在“属性”窗口中,使用“显示所有文件”
,将这些文件夹包括到项目中。没有比这更好的解决办法了。我希望。

一位同事想出了一个解决办法

他建议手动编辑项目,从项目中删除
DefaultTargets
(并删除大量现在未使用的属性)

如果项目中没有目标,MSBuild会抱怨,因此他添加了三个空目标

最终的项目看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.30729</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{541463A7-7CFA-4F62-B839-6367178B16BD}</ProjectGuid>
  </PropertyGroup>
  <ItemGroup>
    ... files ...
  </ItemGroup>
  <ItemGroup>
    ... files ...
  </ItemGroup>
  <Target Name="Build"/>
  <Target Name="Rebuild"/>
  <Target Name="Clean"/>
</Project>

调试
任意CPU
9.0.30729
2
{541463A7-7CFA-4F62-B839-6367178B16BD}
... 文件夹。。。
... 文件夹。。。
诚然,这个解决方案需要更多我希望但似乎实现了我想要的东西:即一个不尝试产生任何构建输出的项目;基本上从项目文件中删除以下行:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

Visual Studio 2015有一个名为“共享项目”的项目类型,它本质上是一个没有目标的纯内容项目。它列在Visual C#下,但可用于任何文件


这个答案只是对Chris Fewtrell和Kenny Evitt给出的上述答案的一个方便的整合,同时对我上面的评论进行了轻微修改,并对内容项声明应该/可能的样子做了更详细的说明:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <ProjectGuid>{541463A7-7CFA-4F62-B839-6367178B16BD}</ProjectGuid>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)' == '64-bit|AnyCPU'">
        <PlatformTarget>x64</PlatformTarget>
        <OutputPath>..\builds\$(Configuration)\</OutputPath>
        <IntermediateOutputPath>..\builds\$(Configuration)\Intermediate\YourProjectName\</IntermediateOutputPath>
    </PropertyGroup>
    <ItemGroup>
        <Content Include="fileInProjectFolder.csv" />
        <Content Include="SubDir\fileInSubdir.txt" />
        <Content Include="..\actualSourceDirectoryOfFile\app.log.basic.config">
          <Link>targetSubdirInOutputDir\app.log.basic.config</Link>
        </Content>
        <Content Include="..\actualSourceDirectoryOfFile\yetAnotherFile.config">
          <Link>yetAnotherFile.config</Link>
        </Content>
        ... more files ...
    </ItemGroup>
    <Target Name="Build">
        <Copy
            SourceFiles="@(Content)"
            DestinationFiles="@(Content->'$(OutputPath)%(RelativeDir)%(Filename)%(Extension)')" />
    </Target>
    <Target Name="Clean">
        <Delete Files="@(Content->'$(OutputPath)%(RelativeDir)%(Filename)%(E‌​xtension)')"/>
    </Target>
    <Target Name="Rebuild" DependsOnTargets="Clean;Build">
    </Target>
</Project>

调试
任意CPU
{541463A7-7CFA-4F62-B839-6367178B16BD}
x64
..\builds\$(配置)\
..\builds\$(配置)\Intermediate\YourProjectName\
targetSubdrinOutputDir\app.log.basic.config
yetAnotherFile.config
... 更多文件。。。

请注意,这将始终将所有“内容”文件复制到输出目录-visual studio GUI中显示的选项“如果较新,则复制”、“始终复制”和“不复制”(例如,.csproj文件中显示为
preservenest
)将被忽略。

在我的情况下,我需要一组配置文件,这些文件对于许多项目来说都是通用的。为了简单地实现这一点,我执行了以下步骤:

  • 创建名为“配置”的类库项目
  • 从配置项目中删除所有*.cs文件
  • 将配置文件放在配置项目的“配置”文件夹中
  • 在生成后事件中将配置文件复制到所需的项目。在配置项目的属性>生成事件>生成后事件中:
  • 在上面的例子中,将TARGET_项目替换为实际项目


    这将把Configurations文件夹中的所有文件复制到需要配置文件的项目的输出目录(例如MyProject/bin/Debug等)谢谢你的回复——我不知道空白的项目模板,但是最终的结果和我现在的一样,也就是说,一个空的C项目需要从构建中被禁用,以防止编译器警告。恐怕我不知道:(。但是,如果这些警告仅来自那些xml或xslt文件。您可以尝试将生成操作设置为资源。因为,您没有以这两种模式中的任何一种进行构建。已根据另一个答复()中的建议更新VS2013并禁用调试属性。您是否考虑过将接受的答案更改为上面讨论的
    共享项目
    ?若要使用TFS Build进行此操作,请不要删除Microsoft.CSharp.Targets的导入,并将
    $(OutputPath)
    的三个实例替换为
    $(OutDir)
    。它仍然可以在本地工作。上面的“干净”目标是危险的。这更好:
    因为如果您有一个包含多个项目的解决方案,所有项目都将其输出放在同一个输出目录中(例如,一起部署的一组库),那么上面的“clean”命令将删除您刚刚构建的所有其他目标。这是一场灾难。事实上,它完全消除了进行“重建”的可能性:在构建顺序中,所有在“内容”项目之前构建的项目都有其目标。不要误会:你的解决方案很棒。值得投票,这正是我们需要的。除了“clean”有点过于激进之外。@kenny evitt:另外,我刚刚注意到你关于vshost文件问题的评论。我也会尝试,如果它有效的话,另一块宝石。谢谢。使用通配符include like in是对共享项目的一个很好的补充,这正是我所需要的。非常感谢。
    <Target Name="Clean">
      <Delete Files="@(Content->'$(OutputPath)%(RelativeDir)%(Filename)%(E‌​xtension)')"/>
    </Target>
    
    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
            <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
            <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
            <ProjectGuid>{541463A7-7CFA-4F62-B839-6367178B16BD}</ProjectGuid>
        </PropertyGroup>
        <PropertyGroup Condition="'$(Configuration)|$(Platform)' == '64-bit|AnyCPU'">
            <PlatformTarget>x64</PlatformTarget>
            <OutputPath>..\builds\$(Configuration)\</OutputPath>
            <IntermediateOutputPath>..\builds\$(Configuration)\Intermediate\YourProjectName\</IntermediateOutputPath>
        </PropertyGroup>
        <ItemGroup>
            <Content Include="fileInProjectFolder.csv" />
            <Content Include="SubDir\fileInSubdir.txt" />
            <Content Include="..\actualSourceDirectoryOfFile\app.log.basic.config">
              <Link>targetSubdirInOutputDir\app.log.basic.config</Link>
            </Content>
            <Content Include="..\actualSourceDirectoryOfFile\yetAnotherFile.config">
              <Link>yetAnotherFile.config</Link>
            </Content>
            ... more files ...
        </ItemGroup>
        <Target Name="Build">
            <Copy
                SourceFiles="@(Content)"
                DestinationFiles="@(Content->'$(OutputPath)%(RelativeDir)%(Filename)%(Extension)')" />
        </Target>
        <Target Name="Clean">
            <Delete Files="@(Content->'$(OutputPath)%(RelativeDir)%(Filename)%(E‌​xtension)')"/>
        </Target>
        <Target Name="Rebuild" DependsOnTargets="Clean;Build">
        </Target>
    </Project>
    
    xcopy "$(TargetDir)Configuration\*" "$(SolutionDir)TARGET_PROJECT\$(OutDir)" /i /v /q /s /y