摘要
旧的.csproj文件,在使用NuGet包的时候,会随着引用一个包,一下子添加n多个包。我们把旧的.csproj文件迁移到最新的格式,就能避免这个问题。
直接上效果
<Project ToolsVersion="12.0" DefaultTargets="Build" Sdk="Microsoft.NET.Sdk.Web" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--这一行从旧版文件予以保留-->
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<ProjectGuid>{4DE0EBFC-2E08-4DC0-9C26-D6B651AE054B}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Yee.Passport.Web</RootNamespace>
<AssemblyName>Yee.Passport.Web</AssemblyName>
<TargetFramework>net481</TargetFramework>
<LangVersion>latest</LangVersion>
<UseIISExpress>true</UseIISExpress>
<!--<OldToolsVersion>4.0</OldToolsVersion>-->
<EnableDefaultContentItems>true</EnableDefaultContentItems>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<CopyRoslynCompilerFilesToOutputDirectory>true</CopyRoslynCompilerFilesToOutputDirectory>
<WebProjectOutputDirInsideProject>false</WebProjectOutputDirInsideProject>
<WebProjectOutputDirInsideProjectDefault>false</WebProjectOutputDirInsideProjectDefault>
</PropertyGroup>
<!--只有这样,这些文件才会发布到目录中-->
<ItemGroup>
<Content Include="Global.asax">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="/*.aspx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="**/*.aspx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="**/*.ascx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="**/*.css">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="**/*.master">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="**/*.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="**/*.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="**/*.gif">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="**/*.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data.Entity" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\Dictionaries\" />
<Folder Include="App_Themes\None\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.3.0" />
<!--这两个包,是因为C#代码里用了动态语言等新特性,需要调用Roslyn编译器。web.config里需要有相应的system.codedom配置-->
<PackageReference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" Version="4.1.0" />
<PackageReference Include="Microsoft.Net.Compilers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!--这个包必须要有-->
<PackageReference Include="MSBuild.Microsoft.VisualStudio.Web.targets" Version="$(MSBuild_Microsoft_VisualStudio_Web_targets_Version)" />
<!--这个是因为引用了基于.NET Standard 2.0的包-->
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="$(Newtonsoft_Json_Version)" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="WebGrease" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hello.World.Core\Hello.World.Core.csproj" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>False</AutoAssignPort>
<DevelopmentServerPort>3595</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:3596/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<!--这个两行都必须要有。MSBuild才能找到_CopyWebApplication这个Target-->
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<!--这是我的原创,加了这个Target,Roslyn的产物才会复制到网站输出目录的bin\roslyn文件夹-->
<Target Name="CopyRoslynCompilerFilesToOutputDirectory2" AfterTargets="_CopyWebApplication">
<ItemGroup>
<RoslynFiles Include="$(CscToolPath)\*" />
</ItemGroup>
<MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
<Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>
</Project>
黑夜里不停折腾的代码行者。